BergP
BergP

Reputation: 3545

Magical record: nil is not a legal NSPersistentStoreCoordinator

I'm using MagicalRecord,

That's how I setup a coreData stack

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

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

That's how 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);
}

That's 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 like core data stack hasn't been set up properly. I've tried changing methods for setting up core data stack, but haven't reached a success.

Upvotes: 4

Views: 690

Answers (1)

You should create Default context, then crete new private context, then set default context as parent for private context

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

NSArray *quizzess = = [Quiz MR_findAllInContext:privateQueueContext];

Upvotes: 1

Related Questions