After iOS modifies the CoreData data structure, the update installation will flash back

Source: Internet
Author: User

If the iOS App is using CoreData and has database updates on the previous version (new tables, fields, and so on), the migration of the CoreData database will be done when the installer is overwritten, as follows:

1. Select your Mydata.xcdatamodeld file, select menu Editor->add Model Version, such as name: Mydata2.xcdatamodel

2. Set the current version

Select Superior Mydata.xcdatamodeld, select the current template as Mydata2 in the versioned Core Data model in Inspector

3. Modify the new data Model MYDATA2, add fields and tables to the new file

4. Delete the original class file and regenerate the following class. (This step is not done)

In the Appdelegate


Nsdictionary *optionsdictionary = [nsdictionary dictionarywithobjectsandkeys:[nsnumber NumberWithBool:YES],
Nsmigratepersistentstoresautomaticallyoption, [NSNumber Numberwithbool:yes],
Nsinfermappingmodelautomaticallyoption, nil];

if (![ Persistentstorecoordinator Addpersistentstorewithtype:nssqlitestoretype
Configuration:nil
Url:storeurl
Options:optionsdictionary
Error:&error]) {

NSLog (@ "Failed to add persistent store with type to persistent store Coordinator");

}

Add *optionsdictionary, original Options:nil changed to Options:optionsdictionary
5. Recompile the program

After iOS modifies the CoreData data structure, the update installation will flash back

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.