0

I have a today extension which uses the same model as the main app and I have had it working before, but now it no longer works.

I get the error * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Cannot create an NSPersistentStoreCoordinator with a nil model'

Things I have done:

Cleaned Build Folder and Cleaned project

Restarted Xcode

Restarted computer

Changed "momd" to "mom"

Ensured the model has the today extension check in the target membership

What else can I do?

- (NSManagedObjectModel *)managedObjectModel
{
    if (_managedObjectModel != nil) {
        return _managedObjectModel;
    }
    NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"Model" withExtension:@"momd"];
    _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];
    return _managedObjectModel;
}
Clip
  • 3,018
  • 8
  • 42
  • 77

1 Answers1

0

I have a shared container for core data access (a framework actually) and I get the model URL in a different way. Maybe you can model your URL retrieval after this:

NSArray *frameworks = [NSBundle allFrameworks];
NSPredicate *dataStorePredicate = 
   [NSPredicate predicateWithFormat:@"bundlePath.lastPathComponent == %@",frameworkName];
NSArray *filteredFrameworks = [frameworks filteredArrayUsingPredicate:dataStorePredicate];
NSBundle *dataBundle = filteredFrameworks.lastObject;
NSURL *modelURL = [dataBundle URLForResource:projectName withExtension:@"momd"];
Mundi
  • 79,884
  • 17
  • 117
  • 140