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

前端 未结 3 2019
逝去的感伤
逝去的感伤 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.

    0 讨论(0)
  • 2021-01-15 18:51

    For future reference and not recommended.

    If the model is unrecoverable, you can "fake it".

    1. Create a new model that is identical to the one you lost
    2. Test it and see if you get lucky (unlikely).
    3. Write down the entity hashes that Core Data spits out in the log
    4. Input those hashes into the model as overrides in the (Version Hash Modifier)
    5. Run your migration again.
    6. Never ever modify the production model again. Check it into source control immediately on shipping.
    0 讨论(0)
  • 2021-01-15 18:54

    For anyone showing up on this question who is not trying to migrate a core data model to another this error can also show up if you are trying to save data to core data that has some values in your entity not being set. Make sure all your data variables are being set and set correctly to avoid this error that dreams of MacBook Pros riding unicorns may live forever in your reality!

    0 讨论(0)
提交回复
热议问题