以前,我使用以下代码为我创建了一个数组,并且它有效。
bundle = [NSBundle mainBundle];
path = [bundle pathForResource:@"MultiSetting" ofType:@"plist"];
settingArray = [[NSMutableArray alloc] initWithContentsOfFile:path];
但在那之后,我想修改 plist 文件,因此,我使用以下代码来执行此操作,但它不起作用。
NSFileManager *mgr = [NSFileManager defaultManager];
NSArray *documentPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentDirectory = [documentPath objectAtIndex:0];
NSString *dstPath = [documentDirectory stringByAppendingPathComponent:@"MultiSetting.plist"];
bundle = [NSBundle mainBundle];
NSString *srcPath = [bundle pathForResource:@"MultiSetting" ofType:@"plist"];
NSError *error = nil;
[mgr copyItemAtPath:srcPath toPath:dstPath error:(NSError **)error];
settingArray = [[NSMutableArray alloc] initWithContentsOfFile:dstPath];
NSLog(@"%@", settingArray);
有什么办法可以解决这个问题吗?我做错什么了吗?