Created
March 8, 2013 21:45
-
-
Save isthisjoe/5120146 to your computer and use it in GitHub Desktop.
Async'ly fetch requests on CoreData
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
// 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