NSPrivateQueueConcurrencyType working outside of performBlock
NSPrivateQueueConcurrencyType working outside of performBlock
- Subject: NSPrivateQueueConcurrencyType working outside of performBlock
- From: Trygve Inda <email@hidden>
- Date: Tue, 28 Jul 2015 06:12:40 -0700
- Thread-topic: NSPrivateQueueConcurrencyType working outside of performBlock
I gather that when using NSPrivateQueueConcurrencyType, all operations (a
fetch for example) have to be done within a performBlock call.
Apple has sample code here:
https://developer.apple.com/library/mac/samplecode/Earthquakes/History/Histo
ry.html#//apple_ref/doc/uid/TP40014547-RevisionHistory-DontLinkElementID_1
That gets a private queue with:
NSManagedObjectContext *privateQueueContext(NSError *__autoreleasing *error)
{
NSPersistentStoreCoordinator *localCoordinator =
[[NSPersistentStoreCoordinator alloc]
initWithManagedObjectModel:[AAPLCoreDataStackManager
sharedManager].managedObjectModel];
if (![localCoordinator addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil URL:[AAPLCoreDataStackManager sharedManager].storeURL
options:nil error:error])
return nil;
NSManagedObjectContext *context = [[NSManagedObjectContext alloc]
initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[context setPersistentStoreCoordinator:localCoordinator];
context.undoManager = nil;
return context;
}
Then later, this context is used outside a performBlock:
NSArray *matchingQuakes = [taskContext
executeFetchRequest:matchingQuakeRequest error:&anyError];
Why does this work?
Trygve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden