CoreData (Database Upgrade) version migration-ios app upgrade installation

Source: Internet
Author: User

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.

In the Appdelegate


The first explanation : my "Coredata_new.xcdatamodeld"--- The entity model has been migrated from Model.xcdatamodeld to Model2.xcdatamodeld, and now I want to move to Model3.xcdatamodeld

Before you begin the operation


Here's how:

First step: Select the Zhongyuan version operation




Step Two: Check the add Model Version ... , there will be

Note: You will see that the new entity model file you created will be created based on your previous version. If there are many versions in front of you, choose which one you'd like to build on, choose the default one, or you'll have to lose the data if you choose an earlier version.

Step three: Click Finish will now be the new entity model Model3.xcdatamodeld, the data will be the same as the original


Fourth step: You can now do your data object operation, the specific data is not operational here


Fifth step: Now we choose the migrated version, go to the first interface, click on the model version, there will be your previous version, select you modify the new version of the data can be



Sixth step: After the selection, such as effect


Seventh Step: Code operation now

1,options system default options is nil, click to go API discovery is a dictionary, so we need to create a Dictionary object

I refine the point: Go into the API and then commad+f in the search bar to enter Autom


2, select the Always enter key to find as



Eighth step: code such as

The Nineth step: According to modify the code can be completed, run successfully.


Other additions,

Several classes used in the CoreData.
(1) Nsmanagedobjectmodel (managed object model)
Equivalent to an entity, but it contains relationships between entities
(2) Nsmanagedobjectcontext (Managed Object context)
Manipulating the actual content
Role: Insert Data query Update delete
(3) Nspersistentstorecoordinator (persistent storage assistant)
A connector equivalent to a database
(4) Nsfetchrequest (Request to get data)
Equivalent to a query statement
(5) Nspredicate (equivalent to query criteria)
(6) Nsentitydescription (solid structure)
(7) A package with a suffix named. Xcdatamodel
The. xcdatamodel file inside, edited with the Data Model Editor
Compiled for. MOMD or. Mom files, which is why there is no such thing in the file, and our program uses this thing without error.

Note: CoreData is an object-relational database, the biggest disadvantage is the thread relationship, can be stored in binary, database, XML format, can have version migration, this is better than SQL, SQL is database storage, object type database

"Coredata_new.xcdatamodeld"---entity model files
SQL gives the string, CoreData to the URL


/**COREDTA steps
* 1 Creating file Model files
* 2 Adding entities
* 3 Creating entity classes
* 4 Build context, parallel data model, generate database
*
Note: CoreData is an object-relational database, the biggest disadvantage is the thread relationship, can be stored in binary, database, XML format, can have version migration, this is better than SQL, SQL is database storage, object type database

"Coredata_new.xcdatamodeld"---entity model files
SQL gives the string, CoreData to the URL
*/

Other: Thank bloggers for sharing: http://mrydblog.com/



Note: This is a personal custom operation, for reference only, if there are errors, please leave a message to indicate.

CoreData (Database Upgrade) version migration-ios app upgrade installation

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.