Core Data light migration on OS X

跟風遠走 提交于 2019-12-02 10:56:34

You mentioned in a comment that you're using the document-based app template-- which is a crucial detail left out of the original question.

With this template you're using a subclass of NSPersistentDocument. If you want to configure migration with NSPersistentDocument, you need to override configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:. Your implementation would call super's implementation with a different set of options. Something like this:

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)
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!