Cannot create an NSPersistentStoreCoordinator with a nil model

前端 未结 27 1060
囚心锁ツ
囚心锁ツ 2021-01-30 03:33

Been having my first crack at Core Data and I\'m getting the following error when running my code on my device, but it works fine on the simulator..

*

27条回答
  •  粉色の甜心
    2021-01-30 04:25

    Okay, I'll tell a half-solution first, it will work if you re-install the app(in simulator or debugger device). But that's not a real solution for sure. For example, if you are updating your application, do NOT do that or your new version may crash because users won't re-install it, they'll use update button instead.

    As I understood, this problem happens mostly when you change the data model file name. The reason might be like this:
    . When you run the app for the first time, it is creating a data model file in app bundle like "data_model_1". This creation happens only for first time.
    . When you update the file name and run the app again, it won't be able to find because there is still "data_model_1" file but you are telling it to look for "data_model_2". How can it find, it has not created it yet and will not unless you don't install the app with new file name.

    So, if this is the first version of your app and re-installing on simulator or device doesn't harm your project, go for it. Else, check Core Data Model Versioning and Data Migration Guide on iOS Developer Library, maybe it's what you need.

    Edit: If reinstalling does not work, try uninstalling first, then cleaning project, then close everything, reopen project and build+run. That should work.

提交回复
热议问题