我正在使用MagicalRecord,
我是如何设置coreData堆栈的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Magical record
[MagicalRecord setupCoreDataStackWithStoreNamed:@"HITO.sqlite"];
我是如何使用它的
- (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);
}
这就是我得到的东西
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''
核心数据堆栈似乎尚未正确设置。 我尝试过更改设置核心数据堆栈的方法,但尚未取得成功。
答案 0 :(得分:1)
您应该创建默认上下文,然后创建新的私有上下文,然后将默认上下文设置为私有上下文的父级
NSManagedObjectContext *mainContext = [NSManagedObjectContext MR_defaultContext];
NSManagedObjectContext *privateQueueContext = [NSManagedObjectContext MR_newPrivateQueueContext];
[privateQueueContext setParentContext:mainContext];
NSArray *quizzess = = [Quiz MR_findAllInContext:privateQueueContext];