Skip to content

Instantly share code, notes, and snippets.

@isthisjoe
Created March 8, 2013 21:45
Show Gist options
  • Save isthisjoe/5120146 to your computer and use it in GitHub Desktop.
Save isthisjoe/5120146 to your computer and use it in GitHub Desktop.
Async'ly fetch requests on CoreData
// assume self.managedObjectContext is a main queue context
NSManagedObjectContext *backgroundContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[backgroundContext performBlock:^{
// do your fetch - e.g. executeFetchRequest
NSManagedObjectID *objID = [someManagedObject objectID];
[self.managedObjectContext performBlock:^{
NSManagedObject *mainManagedObject = [self.managedObjectContext objectWithID:objID];
// do something now with this managed object in the main context
}];
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment