Version Control and migration of CoreData DataModel (simple migration only), coredatadatamodel

Source: Internet
Author: User

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




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.