2
votes

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 = [[NSBundle 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'

1
Do you call [self managedObjectModel] in your persistentStoreCoordinator accessor?Florian Mielke
If you have two data model, check which one is active.karim

1 Answers

2
votes

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.