Magical Record因此消息而崩溃

时间:2014-07-23 07:21:39

标签: ios objective-c core-data magicalrecord

默认上下文为零!您是否忘记初始化核心数据堆栈?

+ (void)saveSplashImageData:(NSString*)data {
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    [SplashImage MR_truncateAllInContext:localContext];
    SplashImage *splashImage = [SplashImage MR_createInContext:localContext];
    splashImage.imageData = data;
    [localContext MR_saveOnlySelfAndWait];
}

+ (SplashImage*)loadSplashImage {
    NSManagedObjectContext *localContext = [NSManagedObjectContext MR_contextForCurrentThread];
    SplashImage *splashImage  = [SplashImage  MR_findFirstInContext:localContext];
    if (splashImage) {
        NSLog(@"Test");
    }
    return splashImage;
}

有任何想法的人如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

将它放在AppDelegate.m中就可以了。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [MagicalRecord setupCoreDataStackWithStoreNamed:@"Flexi.sqlite"];
    return YES;
}