有人能帮我解决这个问题吗?如何将NSMutableDictionary写入plist文件中...
提前致谢。
有人能帮我解决这个问题吗?如何将NSMutableDictionary写入plist文件中...
提前致谢。
请确保你要写入的pList文件位于合法的位置以便进行编辑,例如应用程序沙盒中的“文档”文件夹。 然后找到该位置的路径(如果存在pList文件,则会被覆盖),并使用以下代码:
[myDictionary writeToFile:path atomically:YES];
请告知您目前进展到哪个阶段,可能还需要提供一些代码或错误信息...
[yourDict writeToFile:filePath atomically:YES];
NSData
、NSDate
、NSNumber
、NSString
、NSArray
或NSDictionary
的实例)。而且字典键必须是NSString
对象。NSMutableDictionary *nameDetails=[[NSMutableDictionary alloc] init];
[nameDetails setValue:username forKey:USERNAME_KEY];
[nameDetails setValue:password forKey:PASSWORD_KEY];
NSString *loginDetails = [[NSBundle mainBundle] pathForResource:@"Login" ofType:@"plist"];
[nameDetails writeToFile:loginDetails atomically:YES];
savedStock = [NSMutableDictionary dictionaryWithContentsOfFile:loginDetails];
NSString *pathToPlist = [[NSBundle mainBundle] bundlePath];
pathToPlist = [pathToPlist stringByDeletingLastPathComponent];
pathToPlist = [pathToPlist stringByAppendingPathComponent:@"Documents"];
NSLog(@"%@", pathToPlist; //*
pathToPlist = [pathToPlist stringByAppendingPathComponent:@"Login.plist"];
NSDictionary *nameDetails = @{@"name": @"Albert", @"password": @"emc2"};
[nameDetails writeToFile:pathToPlist atomically:YES];