如何使 iPhone 应用程序能够容忍 CoreData 架构更改
我有一个广泛使用 CoreData API 的应用程序。我正在开发一个更新版本,向实体添加一些字段。由于架构更改,我的应用程序在加载时崩溃(除非我清除私有存储并重新启动)。
问题是当客户升级到新版本时,我不介意在应用程序第一次加载时对其数据运行升级过程,但我什至无法加载它,因为 CoreData 不喜欢架构更改。
有没有什么方法可以告诉 CoreData“没关系..不用担心架构更改”?因为我只添加了字段,没有重命名或删除任何内容。
I have an app that uses the CoreData APIs extensively. I'm developing an updated version that adds a few fields to an entity. My app crashes upon load (unless if I blow away the private storage and start again) because of the schema changes.
The problem is when customers upgrade to the new version, I wouldn't mind running an upgrade procedure on their data the first time the app loads, but I can't even get it to load because CoreData doesn't like that the schema changes.
Is there any way to sort of tell CoreData "Its ok.. don't worry about the schema change"? Because I have only added fields and haven't renamed or deleted anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能应该获得一本 Marcus Zarra 的《Core Data》书并阅读有关迁移的内容(第 5 章)。但是,如果做不到这一点,有一些基础知识是值得了解的。首先,您更新的应用程序中需要旧模型(架构)和新模型。其次,您需要确保新模型被标记为“当前模型”。第三,您需要确保创建 NSPersistentStoreCoordinator 的方式能够自动从现有模型(从磁盘加载)映射到新模型。
更新
新应用中的旧模型需要与旧应用中的模型完全相同。如果您不确定情况是否如此,则可以采取一些步骤来确定。我这样做的方式有点复杂——但如果/当你认为这会有帮助时,我会概述它。
You should probably get a copy of Marcus Zarra's Core Data book and read up on migration (Ch. 5). But, failing that, there are some basics that are good to know. First, you need both your old model (schema) and your new model in your updated app. Second, you need to make sure that the new model is tagged as being the "current model". Third, you need to make sure that you create your NSPersistentStoreCoordinator in such a way that it automatically maps from existing model (as loaded from disk) to new model.
Update
Your old model in your new app needs to be exactly the same as the model in your old app. If you are unsure that this is the case, then there are some steps that you can take to make sure. The way I do it is a bit involved - but I will outline it if/when you think that that would be helpful.