【问题标题】:Magical Record crashing with this messageMagical Record 因此消息而崩溃
【发布时间】:2014-07-23 07:21:39
【问题描述】:

默认上下文为零!你忘记初始化核心数据栈了吗?

+ (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;
}

有人知道如何解决这个问题吗?

【问题讨论】:

  • 你忘记初始化核心数据栈了吗?
  • 谢谢。我想出了如何初始化核心数据堆栈。

标签: ios objective-c core-data magicalrecord


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 2016-01-18
    • 1970-01-01
    • 2018-12-26
    • 2019-05-07
    相关资源
    最近更新 更多