我正在开发一个 iPhone 应用程序,它使用UIManagedDocument
并将其文档存储在 iCloud 上。
一切都工作正常,直到我更改了我的核心数据模型/方案(添加了新的模型版本 - 就像我在过去几周内多次所做的那样)。
我添加了一个新属性并更改了现有属性之一的数据类型。
现在,当我运行我的应用程序时,我似乎无法加载我的文档UIManagedDocument
's -openWithCompletionHandler:
。
我可以创建新文档并读取/写入这些文档。
如果我将数据模型版本改回 1,那么我可以读取现有文档,但不能读取新文档。
据我了解,我只是对数据模型进行轻量级迁移,UIManagedDocument
应该处理这个问题吗?
任何建议将不胜感激!
以下是基于我的理解:
注意 - 我还没有在 iCloud 上尝试过,但我已经在非 icloud 上测试过它,看起来没问题。
UIManagedDocument
配置managedObjectModel
和一个持久存储协调器本身
当需要迁移时,只需设置UIManagedDocument
's persistentStoreOptions
//Note - In this example, managedDocument is a UIManagedDocument property
self.managedDocument.persistentStoreOptions = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];
Refer:
- Apple 关于核心数据版本控制的文档 https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html
- 使用 NSPersistentStoreCoordinator 的要点是什么? https://stackoverflow.com/questions/10729255/point-of-using-nspersistentstorecoordinator
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)