core data “Can't find model for source store”;

前端 未结 3 2039
逝去的感伤
逝去的感伤 2021-01-15 18:10

Heres the problem... I Have an app in the app store, which uses core data... I have been updating my model correctly (using versions etc) but Just recently I have accidental

3条回答
  •  深忆病人
    2021-01-15 18:35

    You can recover the data model from an app store copy of your app, and import that back into your project. Core Data models don't get compiled in the same way that source code does, so reversing the process is usually effective. The following assumes that you have downloaded the current app store version of the app in iTunes on your Mac:

    First copy the app store bundle to a safe place:

    cp ~/Music/iTunes/Mobile\ Applications/YOUR-APP-NAME.ipa /tmp
    cd /tmp/
    

    Next open up that package, which is really just a zip file.

    unzip YOUR-APP-NAME.ipa
    

    This creates a directory called Payload that contains the app and its bundle. The bundle contains the Core Data model. Copy that out of the bundle:

    cp -rp Payload/YOUR-APP-NAME.app/YOUR-MODEL-NAME.momd /tmp/
    

    (adjust the name to match your data model).

    If you already have more than one version in the app store, the model is a momd that contains multiple mom files. Each mom file corresponds to a model version. One of them is the one you need. You'll need to figure out which is which.

    Now, switch to Xcode. Create a new version of the data model but don't make it current. Delete everything in this version, all entities, everything. With the now-empty model displayed, go to the Editor menu and select Import.... In the file open dialog, navigate to the copy of your data model in /tmp/ from above. Select the version you need to recover and click "Open".

    All of the entities from that version of the model are now present in the new model file you just created. You can now use this model as the "original" model when doing model migration.

    Alternatively, instead of importing into Xcode, you can use my momdec project to decompile the model in place. That will produce an uncompiled Core Data model that you could add to your Xcode project.

提交回复
热议问题