我使用基于Xcode 6文档的应用程序和OS的核心数据模板,它在幕后设置核心数据堆栈(没有可见的init代码)。现在,我需要执行一个简单的核心数据轻量级迁移,我已经创建了新的版本化模型并激活了它。我真的必须手动实现核心数据堆栈初始化才能传递迁移权限吗?如果是,核心数据堆栈应该在哪里初始化,以便覆盖默认值?
发布于 2015-04-21 15:50:39
您在评论中提到,您使用的是基于文档的应用程序模板--这是一个关键的细节,没有出现在最初的问题中。
使用此模板,您将使用NSPersistentDocument的子类。如果要使用NSPersistentDocument配置迁移,则需要重写configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:。您的实现将使用不同的选项来调用super的实现。如下所示:
override func configurePersistentStoreCoordinatorForURL(url: NSURL!, ofType fileType: String!, modelConfiguration configuration: String?, storeOptions: [NSObject : AnyObject]!, error: NSErrorPointer) -> Bool {
let options = [ NSMigratePersistentStoresAutomaticallyOption : true,
NSInferMappingModelAutomaticallyOption: true ]
return super.configurePersistentStoreCoordinatorForURL(url, ofType: fileType, modelConfiguration: configuration, storeOptions: options, error: error)
}https://stackoverflow.com/questions/29770959
复制相似问题