How to migrate new data model in a CoreData project?
I have a simple problem, I have an app based on CoreData and I need to change the structure a little. How can I migrate the old structure into the new one. 开发者_运维技巧Just adding one attribute will chrash the whole app.
Thanks
Have a look at the Apple Docs
http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/CoreDataVersioning/Introduction/Introduction.html
Once you have the basics of Core Data down, you can implement versioning. Until then, if you're just testing things out, you can always delete the app from the Simulator or device. Reinstalling the app will create a fresh data store (usually).
When you finally do get to the point where you want to version, you add a new one by clicking on your core data model file (YourApp.xcdatamodel). Then pull down the 'Design' menu, hover on 'Data Model', and click 'Add Model Version'.
Don't forget to change your model extension from 'mom' to 'momd' (wherever you're loading it, probably in your app delegate), and when you have your new version in hand, go back to that menu and click 'Set Current Version'.
精彩评论