Migrating Core Data - how to do it safely?
I have an app released, and I want to release a new version.
The new version has a very small change in the Core Data model: adding a BOOL a开发者_开发百科ttribute ("hasUpdated") to an entity ("Users").
How would I migrate without the app crashing after being updated (obviously) or changing the existing data?
First, make sure the data model you are using (with the new BOOL attribute) is a different version than the one that you have released. To create a new model I believe it's something like Editor -> Add Model Version -> and then name it / tell it which model to be based from.
Now set the new model as the current version in the utility pane. For help on this check out this post: Xcode 4, Core Data Model Version - Set Current Version
For such a simple change you should be able to tell the persistent store to perform lightweight migration. This post should explain that: Implementation of "Automatic Lightweight Migration" for Core Data (iPhone)
精彩评论