默认上下文为零!您是否忘记初始化核心数据堆栈?
+ (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;
}
有任何想法的人如何解决这个问题?
答案 0 :(得分:0)
将它放在AppDelegate.m中就可以了。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[MagicalRecord setupCoreDataStackWithStoreNamed:@"Flexi.sqlite"];
return YES;
}