I'm developing a TodayExtension for a productivity app of task lists and I need to show a list of some tasks in a table inside the TodayExtension.
I don't have any problem setting up the table view but I have a crash when I'm trying to set up MagicalRecord and CoreData.
My source code for the method that crash is:
- (void)setupCoreDataStackWithStoreNamed:(NSString *)storeNamed
{
if ([NSPersistentStoreCoordinator MR_defaultStoreCoordinator] != nil)
{
return;
}
NSManagedObjectModel *model = [NSManagedObjectModel MR_defaultManagedObjectModel];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:model];
NSString *containerPath = [[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:APP_GROUP].path;
NSString *sqlitePath = [NSString stringWithFormat:@"%@/%@", containerPath, storeNamed];
NSURL *storeURL = [NSURL URLWithString:sqlitePath];
[psc MR_addSqliteStoreNamed:storeURL withOptions:nil];
[NSPersistentStoreCoordinator MR_setDefaultStoreCoordinator:psc];
[NSManagedObjectContext MR_initializeDefaultContextWithCoordinator:psc];
}
And the line with the crash is:
[psc MR_addSqliteStoreNamed:storeURL withOptions:nil];
The error message is:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'CoreData SQL stores only support file URLs (got /private/var/mobile/Containers/Shared/AppGroup/66A40F3A-9E25-42BD-9BD0-D86BC5A93FBD/myappname_560967e1665e88ab37000000.sqlite).'
I got the inspiration from this post How to access CoreData model in today extension (iOS)