Version Control and migration of CoreData DataModel (simple migration only), coredatadatamodel
CoreData APP usedEach time a new version is releasedYou must create a new data model. Otherwise, it is easy for old users to Crash after upgrade.
In Xcode, click XXXXX. xcdatamodel, click the Editor menu, select Add Model Version, and enter the name of the new Version. Click Finish.
Generated XXXXX 2. xcdatamodel is a data model of the old version, which is checked by XXXXX. xcdatamodel is the data model to be released in the new version. The higher the version number, the older the file. When you create another version, the old version will be named XXXXX 3. xcdatamodel, with the accumulation of versions, the significance of these numbers gradually emerges.
CoreData supports two different types of migration. Lightweight migration and standard migration.
If you have added or removed attributes in an object or added or deleted an object in a data model, you can perform lightweight migration. However, if you split an object into two different entities, you can also move an attribute from one object to another. Lightweight migration is invalid and requires standard migration.
Most common modifications can be completed by lightweight migration.
The method is to partially modify the persistentStoreCoordinator method of AppDelegate.
Set
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {
Change
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption:@YES,NSInferMappingModelAutomaticallyOption:@YES}; if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
You can.
For standard migration, see:
https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/Introduction.html
PS: whether it is standard migration or lightweight migration, a large number of tests are required before the APP goes online to ensure that the version update will not cause Crash due to the upgrade of the data model.
Reprinted please indicate the original:Http://blog.csdn.net/marvindev