Cannot create an NSPersistentStoreCoordinator with a nil model

前端 未结 27 1007
囚心锁ツ
囚心锁ツ 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:05

    For me the problem was due to the fact that I copy pasted my model from a sandbox project to my actual project. Always make sure to generate your model from within the project that the model is being used.

    0 讨论(0)
  • 2021-01-30 04:06

    I had this problem and changing "moms" to "mom" didn't do anything. To fix it I had to right click on the xcdatamodelId file > show package contents then delete the hidden .xcurrentversion file.

    P.S: This problem only started happening after I'd changed the name of the data model file.

    0 讨论(0)
  • 2021-01-30 04:07

    I had the same problem, it worked fine on iOS6 but not on iOS5. This is how I solved it:

    1. Create a new Model version in xcode. (select the .xcdatamodeld, open the Editor menu and click "Add Model Version...")
    2. Compile and make sure that the new version works.
    3. Set the old one as current version. ("Current" in File Inspector for the .xcdatamodeld under Versioned Core Data Model)
    4. Remove reference to the .xcdatamodeld file in xcode
    5. Right click the .xcdatamodeld file in Finder and choose "Show Package Contents"
    6. Delete the new .xcdatamodel that you dont want
    7. Re-add the .xcdatamodeld in xcode
    8. Compile and smile

    (This is where I found how to delete a Model version: How to delete an old/unused Data Model Version in Xcode)

    0 讨论(0)
  • 2021-01-30 04:08

    After I fixed the naming issue, the error remained. Then it worked after restarting Xcode 5. This might automatically do the same thing as some of the manual linking suggestions offered here.

    0 讨论(0)
  • 2021-01-30 04:09

    I had the same issue, i.e.

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyModel" withExtension:@"momd"];
    

    returned nil, because there was no .momd file generated.

    The reason was that in the app directory (e.g. MyGreatApp/MyGreatApp.app) xcode had copied the MyModel.xcdatamodeld instead of generating the MyModel.momd from the MyModel.xcdatamodeld file (using momc).

    The solution was to delete the reference to MyModel.xcdatamodeld inside the XCode project browser and drag it back into the project from the finder. After that xcode realized it needed to compile it to a .momd.

    0 讨论(0)
  • 2021-01-30 04:10

    The solution to the problem you speak of is simple. Change the file extension to "mom" instead of "momd" in the model URL. Done.

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