Cannot create an NSPersistentStoreCoordinator with a nil model

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

    I had the same problem. The solution was a mix of 2 answers:

    1) I had to add the "subdirectory" parameter into the URLForResource call

    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"DATAMODEL_NAME" withExtension:@"mom" subdirectory:@"DATAMODEL_NAME.momd"];
    

    2) For a reason I don't know, the data model was not included when the project was compiled. I had to add it manually into the "Build Phases / Compile resources".

    With only one of the above solutions, my application didn't work.

提交回复
热议问题