Core X上的核心数据光迁移 [英] Core Data light migration on OS X

查看:293
本文介绍了Core X上的核心数据光迁移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用基于Xcode 6文档的应用程序和核心数据模板OS X,它设置了核心数据栈后面(没有可见的init代码)。现在我需要执行一个简单的核心数据轻量级迁移,我已经创建了新的版本化模型并激活它。我真的必须手动实现核心数据栈初始化才能够通过迁移权限?如果是的话,核心数据栈应该在哪里初始化,以便它将覆盖默认值。

I'm using the Xcode 6 document based application with core data template for OS X, which sets up the core data stack behind the scenes (no visible init code). Now I need to perform a simple core data lightweight migration and I have created the new versioned model and activated it. Do I really have to implement the core data stack initialisation by hand just to be able to pass migration permissions? If yes, where should the core data stack be initialised so that it will override the default?

推荐答案

您正在使用基于文档的应用程序模板 - 这是原始问题中留下的一个至关重要的细节。

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.

使用此模板,您使用的子类 NSPersistentDocument 。如果要使用 NSPersistentDocument 配置迁移,您需要覆盖 configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error:。您的实现将使用不同的选项集来调用 super 的实现。这样的东西:

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)
}

这篇关于Core X上的核心数据光迁移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆