Skip to content

Instantly share code, notes, and snippets.

@jonahsiegle
Created March 27, 2014 04:09
Show Gist options
  • Save jonahsiegle/9800029 to your computer and use it in GitHub Desktop.
Save jonahsiegle/9800029 to your computer and use it in GitHub Desktop.
//Access the oppropriate entity
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Task" inManagedObjectContext:((AppDelegate *)[[UIApplication sharedApplication]delegate]).managedObjectContext];
//Creating a child context to use in the background thread
NSManagedObjectContext *context = [[NSManagedObjectContext alloc]initWithConcurrencyType:NSPrivateQueueConcurrencyType];
//Setting the parent context
context.parentContext = ((AppDelegate *)[[UIApplication sharedApplication]delegate]).managedObjectContext;
//Call fetching in background
[context performBlock:^{
NSFetchRequest *request = [[NSFetchRequest alloc]init];
//Setting the entity (table) to be fetched
[request setEntity:entity];
NSError *error = nil;
//Array pupulated with the objects
NSMutableArray *resultsArray = [[NSMutableArray alloc]initWithArray:[context executeFetchRequest:request error:&error]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment