Magic Record: nil is not legal NSPsistentStoreCoordinator

I am using MagicalRecord,

The way I install the coreData stack p>

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Magical record

    [MagicalRecord setupCoreDataStackWithStoreNamed:@"HITO.sqlite"];

The way I use it

- (void)getQuizzessWithCompletion:(void(^)(NSArray *quizzess, BOOL succes, NSError *error))completion {
    NSManagedObjectContext *backGroundContext = [NSManagedObjectContext MR_newPrivateQueueContext] ;
    NSArray *quizzess = [Quiz MR_findAllInContext:backGroundContext];
    BlockSafeRun(completion, quizzess, YES, nil);
}

What i get

2015-06-17 19:50:53.358 HITO[6677:611576] Created new private queue context: <NSManagedObjectContext: 0x61f990>
2015-06-17 19:50:57.230 HITO[6677:611576] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+entityForName: nil is not a legal NSPersistentStoreCoordinator for searching for entity name 'Quiz''

enter image description here

It seems that the main data stack is not configured properly. I tried to change the methods for setting up the main data stack, but did not succeed.

+4
source share
1 answer

You must create a default context, then create a new private context, and then set the default context as the parent for the private context

NSManagedObjectContext *mainContext = [NSManagedObjectContext MR_defaultContext];
NSManagedObjectContext *privateQueueContext = [NSManagedObjectContext MR_newPrivateQueueContext];
[privateQueueContext setParentContext:mainContext];

NSArray *quizzess = = [Quiz MR_findAllInContext:privateQueueContext];
+1
source

All Articles