Anything that involves the NSManagedObjectContext
of NSPrivateQueueConcurrencyType
should be wrapped in a performBlock
block. For background fetching where you want to pass managed objects back to the main queue's context, something like this: (note this is just for illustrative purposes):
// 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
}];
}];