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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to