Coredata lightweight migration experience

Source: Internet
Author: User

 

 

Coredata has a small amount of related information on the Internet, most of which are basic usage. So I found the official documents of apple for further study.

Share your experiences. If coredata is used, you must understand coredata migration. Otherwise, the app version may encounter persistent coredata errors due to the change in the core data model schema,ProgramCrash.

Lightweight migration can be used to migrate data to the new model in the following situations.

Nsdictionary * Options = [ Nsdictionary Dictionarywithobjectsandkeys :[ Nsnumber Numberwithbool : Yes ], Nsmigratepersistentstoresautomaticallyoption ,[ Nsnumber Numberwithbool : Yes ], Nsinfermappingmodelautomaticallyoption , Nil ];

_ Persistentstorecoordinator= [[NspersistentstorecoordinatorAlloc]Initwithmanagedobjectmodel:[SelfManagedobjectmodel];

If(! [_ PersistentstorecoordinatorAddpersistentstorewithtype:NssqlitestoretypeConfiguration:NilURL: StoreurlOptions: OptionsError: & Error])

// OthersCode

-------------- Several situations are summarized as follows --------------------

1, simple addition of a new attribute. (add an attribute to an entity)

2. Removal of an attribute. (delete an attribute for an entity)

3, a non-optional attribute becoming optional.

4, an optional attribute becoming non-optional,And defining a default value.

5,Renaming an entity or property.

 

    • Adding relationships and changing the type of relationship

      • You can add a new relationship or delete an existing relationship.

      • Renaming a relationship (by using a renaming identifier, just like an attribute)

      • Changing a relationship from a to-one to a to-random, or a non-ordered to-random to ordered (and visa-versa)

    • Changing the entity hierarchy

      • You can add, remove, rename entities

      • You can create a new parent or child entity and move properties up and down the entity hierarchy

      • You can move entities out of a hierarchy.

 

<Note>YouCannot, However, merge entity Hierarchies; if two existing entities do not share a common parent in the source, they cannot share a common parent in the destination. In this case, lightweight migration cannot be used.

Official documentation:

Https://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmLightweightMigration.html#//apple_ref/doc/uid/TP40004399-CH4-SW1

NextCore data model mapping

 

 

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.