gpt4 book ai didi

objective-c - 添加新的核心数据模型版本后出错

转载 作者:行者123 更新时间:2023-12-04 02:46:01 25 4
gpt4 key购买 nike

我添加了一个新的模型版本,并将核心数据模型设置为使用该新版本,但是当应用程序尝试启动时出现此错误。

“用于打开持久存储的托管对象模型版本与用于创建持久存储的版本不兼容。”

enter image description here

我猜问题是当前的持久存储是模型的旧版本。有没有办法只删除它以便创建一个新的?我不关心保存任何数据。

最佳答案

您必须在版本之间迁移。按照苹果的文档,如果改动简单,可以做轻量级迁移。

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweight.html#//apple_ref/doc/uid/TP40008426-SW1

将这些选项添加到 NSPersistentStoreCoordinator 似乎可行。

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"YOURAPP.storedata"];
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];
if (![persistentStoreCoordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:options error:&error]) {
[[NSApplication sharedApplication] presentError:error];
[persistentStoreCoordinator release], persistentStoreCoordinator = nil;
return nil;
}

return persistentStoreCoordinator;

关于objective-c - 添加新的核心数据模型版本后出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5572954/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com