后台更新核心数据的更新版本。
在与 CoreData链接Grand Central Dispatch (GCD)的帮助下,创建了一个后台 managedObjectContext 但从核心数据获取时出现错误
-(void) startTimerThread
{
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] init];
self.backgroundManagedObjectContext = context;
[self.backgroundManagedObjectContext setPersistentStoreCoordinator:self.managedObjectContext.persistentStoreCoordinator];
self.managedObjectContext = self.backgroundManagedObjectContext;
[self getDataFromFile];
dispatch_async( dispatch_get_main_queue(), ^{
// Add code here to update the UI/send notifications based on the
// results of the background processing
[[NSNotificationCenter defaultCenter] postNotificationName:@"ReloadAppDelegateTable" object:nil];
[context release];
self.managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
});
});
}
在getDataFromFile
我尝试从中获取时出现错误managedObjectContext
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setPredicate:[NSPredicate predicateWithFormat:@"date == max(date)"]];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"LogDetails" inManagedObjectContext:self.managedObjectContext];
同样的错误:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name LogDetails
谁能告诉我为什么我得到这个错误。以前我试图创建一个子 managedObjectContext ,它给出了同样的错误。
提前致谢。