UPDATED Version of core data update in background.
with the help of link Grand Central Dispatch (GCD) with CoreData created a background managedObjectContext but I am getting an error when fetching from core data
-(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];
});
});
}
and in my getDataFromFile
I am getting error when I try to fetch from managedObjectContext
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setPredicate:[NSPredicate predicateWithFormat:@"date == max(date)"]];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"LogDetails" inManagedObjectContext:self.managedObjectContext];
the same error :
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '+entityForName: could not locate an NSManagedObjectModel for entity name LogDetails
can anyone suggest me why i m getting this error. Previously I was trying to create a child managedObjectContext which was giving same error.
Thanks in advance.