我需要基本更新在后台线程我的核心数据,而不阻塞UI和保存。 节约应该重新加载表视图以查看更改后。 因此,对于这样做我想用的
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// Add code here to do background processing
NSManagedObjectContext *context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
self.backgroundManagedObjectContext = context;
if(self.managedObjectContext == nil)
self.managedObjectContext = [(AppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
self.backgroundManagedObjectContext.parentContext = self.managedObjectContext;
//update data
[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];
});
});
在getDataFromFile当我试图获取数据
if(![NSThread isMainThread])
{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"LogDetails" inManagedObjectContext:self.backgroundManagedObjectContext];
[request setEntity:entity];
logs = [self.backgroundManagedObjectContext executeFetchRequest:request error:nil];
}
我得到的错误*终止应用程序由于未捕获的异常“NSInternalInconsistencyException”,原因是:“+ entityForName:未能找到NSManagedObjectModel的实体名称‘LogDetails’”
任何人都可以解释为什么我收到此错误
另外我有一个又一个疑问,是否与父母为主线managedObjectContext它作为背景managedObjectContext或儿童managedObjectContext