Use MagicalRecord (CoreData) inside TodayExtension
<p>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.</p>

<p>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.</p>

<p>My source code for the method that crash is:</p>

<pre><code>- (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];
}
</code></pre>

<p>And the line with the crash is:</p>

<pre><code>    [psc MR_addSqliteStoreNamed:storeURL withOptions:nil];
</code></pre>

<p>The error message is:</p>

<pre><code>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).'
</code></pre>

<p>I got the inspiration from this post <a href="https://stackoverflow.com/questions/25407428/how-to-access-coredata-model-in-today-extension-ios">How to access CoreData model in today extension (iOS)</a></p>