我的 plist 是一个array with dictionaries
.
在启动时,如果 .plist不存在,则从bundle
to复制它。documents directory
但是如果 plist 已经存在于documents directory
:
必须根据包中更新的双字典检查每个字典,以查找“District”字符串中的更改。
当然,如果进行了更改,请替换字符串。
这是复制 plist 函数:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self copyPlist];
return YES;
}
- (void)copyPlist {
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"Wine.plist"];
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"Wine" ofType:@"plist"];
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath: path]) {
[fileManager copyItemAtPath:bundle toPath:path error:&error];
} else {
//I need to check if the "District" value has been changed in any of the dictionaries.
}
}
关于如何做到这一点的任何建议,或有用的教程/示例代码?
我的猜测是我必须将 plist 的内容提取到 NSMutableArrays:bundleArray
和documentsArray
. 然后在数组中找到匹配的字典。可以通过查看“名称”字符串是否相等来完成。然后比较匹配字典中的两个“District”字符串并查找任何更改,并替换更改的。但我不知道应该怎么做,所以任何帮助都非常有用,因为这非常重要!