Core Data model Is throwing Exception
I am using core data in my app. My app was working fine.. I recently reset my simulator setting and now that app is throwing exception. I read all posts and clean my target also but it is not running ,,then I set breakPoint and found exception in last line of this code
- (NSManagedObjectModel *)managedObjectModel {
if (managedObjectModel_ != nil) {
return managedObjectModel_;
}
NSURL *modelURL = [[NSBun开发者_如何学Godle mainBundle] URLForResource:@"TouristGuide" withExtension:@"momd"];
managedObjectModel_ = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
return managedObjectModel_;
}
This code is in my APPdelegate file.. And Exception is
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'
As the error says, the model seems to be nil, or rather the modelURL
. You can see this by adding NSLog(@"%@", modelURL)
, it will print (null)
.
Make sure that your model is really called TouristGuide
and is in the mainBundle
, i.e. gets added when building.
精彩评论