Beginner Core Data Gotcha
When getting started with the CoreData framework, a common error you might run into when trying to test out your initial data model is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
Clearly this isn't a very helpful exception. What do you mean nil model? I remember creating my model, how could it be nil?
The likely fix turns out to be painfully obvious. There may be a mismatch between the name of your object model file and the name being referenced in the managedObjectModel method.
First, open up the Project Navigator and check the name of the object model file. For example, let's say the object model file is named MyAppModel.xcdatamodelid. Now, we need to make sure that name corresponds to the name used in the App Delegate file.
Open up your app delegate file which is probably called something like XYZAppDelegate.m. Find the managedObjectModel method and check that the URLForResource argument in the following line of code matches your object model file name:
NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"MyAppModel" withExtension:@"momd"];
If this is where the mismatch was, try running your application again. If this wasn't where the problem was, then you might have to do a bit more searching.