Created
March 27, 2014 04:09
-
-
Save jonahsiegle/9800029 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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