ios - Migrating Core Data and Mapping Model -


i hope fine :)

i have database using core data. in application v1.0, users can import file in apps. now, v2.0, add attribute in model, users have v1.0 , have stored files have hold files (no deleting if upgrade app...). so, created new data model new attribute, , set current versioned core data model new data model... ok. if launch app, file deleted.

normally, have use mapping model. how ? source data model , destination data model when i'm creating mapping model ?

thank help! have day all! :)

edit:

if add new attribute not edit names of attributes, maybe don't need create mapping model... no ?

if using mapping model, source model v1.0 model , destination new v2.0 model. may able away without using mapping model using lightweight migration, documentation here.

the gist of says you'll need go app delegate , set relevant options persistent store.

it should like

nsdictionary *options = @{nsmigratepersistentstoresautomaticallyoption: @yes, nsinfermappingmodelautomaticallyoption: @yes};  [persistentstorecoordinator addpersistentstorewithtype:storetype configuration:config url:storeurl options:options error:&error]; 

the nsmigratepersistentstoresautomaticallyoption key tells core data check if current managed object model version different store you're using , migrate store updated model. nsinfermappingmodelautomaticallyoption tells try work mapping out itself. 'lightweight migration' bit.

most of there, need add options dictionary. in - (nspersistentstorecoordinator *)persistentstorecoordinator method. if don't set @ least nsmigratepersistentstoresautomaticallyoption no migration take place.

lightweight mapping useful while developing. means can make changes model without needing redo mapping every time.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

monitor web browser programmatically in Android? -

c# - Using multiple datasets in RDLC -