Cannot create an NSPersistentStoreCoordinator with a nil model Cannot create an NSPersistentStoreCoordinator with a nil model ios ios

Cannot create an NSPersistentStoreCoordinator with a nil model


I had exactly the same error message as the original post. I was wrestling with this for hours.It was this line in my AppDelegate.m.

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"[same with name of xcdatamodeld]" withExtension:@"momd"];

For anyone out there searching this error message and finding this thread....try this first.

You must make sure that where it says [same with name of xcdatamodeld]....that it is!!!For some reason, mine had my project name in there and not the data model name.

Changed it and it worked straight away.....

Thanks to Rock & Muller for contributing.......you saved me days!!

Gaz.


first verify:

NSLog(@"%@", [self managedObjectModel]);

If you get a nil value maybe the problem is here

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

So, try changing @"momd" by @"mom"


I've experienced a weird issue with Xcode 4.3.2 and iOS 5.

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

returns a valid URL but

__managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

returns a null NSManagedObjectModel. But after checking the documentation, it seems like NSManagedObjectModel needs a file where as NAME_OF_THE_MODEL.momd is a directory which contains a NAME_OF_THE_MODEL.mom file. Changing the URL to

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

then works. Seems weird though that Xcode generates code that doesn't work with itself...