Upgrade and install iOS app-upgrade coredata Database

Source: Internet
Author: User

If the iOS app uses coredata and has database updates (new tables, fields, and other operations) in the previous version, overwrite the installationProgramTo migrate the coredata database, perform the following operations:

1. Select Your mydata. xcdatamodeld file and choose editor> Add model version from the menu, for example, mydata2.xcdatamodel.
2. Set the current version
Select the parent mydata. xcdatamodeld, and select the current template as mydata2 in versioned core data model of inspector.

3. Modify the new data model mydata2 and add fields and tables to the new file.

4. Delete the original class file and regenerate the next class.

In appdelegate

[HTML]
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]) {www.2cto.com

Nslog (@ "failed to add persistent store with type to persistent store coordinator ");

}
Add * optionsdictionary. The original options: Nil is changed to options: optionsdictionary.

5. recompile the program.

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.