Search code examples
iosxcodecore-dataxcdatamodel

How to recreate xcdatamodeld


I am maintaining an app that has been live on the AppStore for a few months. My app uses Core Data and somehow I managed to lose all previous versions of my xcdatamodel.

I am hoping to perform a lightweight migration. All I need to do is add one attribute to one of my entities. So, I have followed the correct steps of creating a model version.

Apparently, I modified the original xcdatamodel. So, when I test the migration, it fails with an error Code=134130 "Can't find model for source store". Since the app runs fine when there is no sqlite file on the device/simulator, I've concluded that the original xcdatamodel has been modified.

Assuming my logic thus far holds, how can I create an xcdatamodel that will match the sqlite files on my users' devices. It's not acceptable for them to lose their data.

Thank you.


Solution

  • With a Core Data model file open (eg a blank one), choose Editor -> Import, and then find the .mom file from the previous version of your app.

    See this answer.