Core Data Database Migration

Source: Internet
Author: User

First, lightweight migration

I. Suitable for the scene

Simple addition of a new attribute

Removal of an attribute

A non-optional attribute becoming optional

An optional attribute becoming non-optional, and defining a default value

Renaming an entity or property

II. How to Do

1. Set Persistent Store:

Nsdictionary *persistentstoreoptions = @{nsmigratepersistentstoresautomaticallyoption: @YES,

Nsinfermappingmodelautomaticallyoption: @YES};

PersistentStore = [_persistentstorecoordinator addpersistentstorewithtype:nssqlitestoretype configuration:nil URL: Storeurl options:persistentstoreoptions error:&addstoreerror];

2. Add a version to Database.xcdatamodel

Select Database.xcdatamodel, Editor, Add Model Version, and then set which data model file for the current database is the right one.

3. This will be done. So easy and simple. And this kind of migration mode, occupy most of database data migration application scenario.

Second, multiple Passes

This technology, I have not yet encountered the need to use its scene, so did not take the time to study. As for how to deal with, can refer to a very good blog, http://www.cnblogs.com/liyufeng2013/p/3782351.html

Apple official doc:https://developer.apple.com/library/prerelease/ios/documentation/cocoa/conceptual/ Coredataversioning/articles/vmmappingoverview.html#//apple_ref/doc/uid/tp40004399-ch5-sw1

Core Data Database Migration

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.