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.
<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