Cannot create an NSPersistentStoreCoordinator with a nil model

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

提交回复
热议问题