在iPhone应用程序中修改和保存plist

时间:2013-11-12 16:43:27

标签: ios objective-c

我有一个iPhone应用程序,我必须在运行时修改plist。我成功地能够在模拟器上完成它,但是当我在设备上运行它时,它从旧的plist中检索数据并且没有进行修改。这是我用来获取plist路径的代码 -

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Customer.plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];

if (![fileManager fileExistsAtPath: path])
{
    path = [[NSBundle mainBundle] pathForResource:@"Customer" ofType:@"plist"];
}



NSMutableDictionary *mainDictionary;
mainDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile: path];

1 个答案:

答案 0 :(得分:0)

要在plist文件上写一个字典,这行可行

[dicionaryToWrite writeToFile:path atomically: TRUE];