I have this special case scenario, where in my app works perfectly fine for some time and crashes inconsistently after some time. The error that i get during the crash is "Cannot create an NSPersistentStoreCoordinator with a nil model".
I tried debugging my app and found that the managedObjectModel
is returning NULL
sometimes. To add fuel to the fire, this scenario is not at all consistent. For some time the managedObjectModel
is fine. But, suddenly it returns NULL
...
Here is the code that I am using to create a managed object model.
- (NSManagedObjectModel *)managedObjectModel
{
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSBundle *newBundle = [NSBundle bundleWithURL:[[NSBundle mainBundle] URLForResource:@"dataBundle" withExtension:@"bundle"]];
NSString *modelPath = [newBundle pathForResource:@"DataHouse" ofType:@"momd"];
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
NSLog(@"managedObjectModel_ %@", [managedObjectModel_ entities]);
return managedObjectModel_;
}
As you can see above, due to some special requirements, I have placed my .xcdataModeld file in a separate bundle and referencing it from there. I got struck and need some help.... Thanks