我已向现有Plist添加新实体。由于Plist不一致,新版本的应用程序崩溃。
如何将旧plist数据与新plist合并?
我的Plist创建方法如下
- (void)createEditableCopyOfFileIfNeeded:(NSString *)plistName
{
// First, test for existence.
BOOL success;
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *plistPath = [documentsDirectory stringByAppendingPathComponent:plistName];
success = [fileManager fileExistsAtPath:plistPath];
if (success)
{
return;
}
// The writable database does not exist, so copy the default to the appropriate location.
NSString *defaultPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:plistName];
success = [fileManager copyItemAtPath:defaultPath toPath:plistPath error:&error];
if (!success)
{
NSAssert1(0, @"Failed to create writable database file with message '%@'.", [error localizedDescription]);
}
}
提前致谢
答案 0 :(得分:2)
我会在你的plist中包含一个 version 键,以便将它与应用程序的版本进行比较。您可以使用以下代码段检查应用程序的版本:
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]
然后,在应用程序启动时:
答案 1 :(得分:0)
你可以这样做: