ios - I didn't migrate NSPersistentStore in new version, can I recover with an app update? -


long story short, core data schema changed, , app submitted app store, caused updated app crash. crash caused missing nspersistentstore due not migrating data model properly.

i still see .sqlite , associated database files in documents directory, , if downgrade older version works fine data. question is, can recover app update somehow migrating existing nspersistentstore , adding nspersistentstorecoordinator?

edit: didn't change xcdatamodel myself, hence, "long story short". however, did remove xmppframework project , have feeling might have caused core data problem.

edit:
didn't make changes directly data model, have pinpointed problem. retrieving nsmanagedobjectmodel using [nsmanagedobjectmodel mergedmodelfrombundles:nil] merges data models present in bundle. included data models came xmppframework, , framework has been removed, nsmanagedobjectmodel passed [[nspersistentstorecoordinator alloc] initwithmanagedobjectmodel] different, causing crash.

i resolved problem using fmdb fetch contents of existing db, created new sqlite file , pointed persistent store coordinator new sqlite file. inserted existing data new database looping through existing data , creating appropriate nsmanagedobjects. stopped using mergedmodelfrombundles retrieve data model , instead use initwithcontentsofurl.

actually might have updated xcdatamodel somehow after first version, , didn't created new xcdatamodel model second version. on second update it's crashing.

note: after first version release, have create second model version of xcdatamodel.

to create second model version of xcdatamodel -
1. first have select model.xcdatamodeld -> go editor on menu -> add model version. here have name model version , based on old model want create new one.
whatever changes want make should make on new model version xcdatamodel.

enter image description here

2. can see on image, i've given new name new model 'model2.0', based on previous 'model'.
new model work old model, additionally changes made on new model won't affect old model. won't crash app after update.
3. have select new 'model2.0' default working model. please consider below image.

enter image description here

4. here can see there 2 model now. please select 'model.xcdatamodeld' main model, , open it's 'file inspector' on right side - opened on above image.

5. there 'model version' field on right side, indicates 'current' model selected on project. please select new model 'model2.0' updated version. can run , work fine onwards.

note: please make sure whatever changes make, on new model 'model2.0', won't conflict old model. have make new model each time, if want change configuration of xcdatamodel on updated app version.


Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -