I need the concurrence type of NSPersistentDocument's managedObjectContext to be NSMainQueueConcurrencyType because I need contexts in other threads.
Asked
Active
Viewed 127 times
2 Answers
4
The documentation for NSPersistentDocument
says this about the managedObjectContext
property:
If you want to customize the creation of the persistence stack, reimplement this property in your custom subclass and use your implementation to create the appropriate objects.
That seems pretty clear. Override this property and use whatever concurrency type you want. Have you tried it? Did it not work?

Tom Harrington
- 69,312
- 10
- 146
- 170
1
Yes, you were right. Overriding manageObjectContext you can modify concurrency type. Maybe, I have some mistakes.
- (NSManagedObjectContext *)managedObjectContext {
__strong static NSManagedObjectContext *myManagedObjectContext = nil;
if (myManagedObjectContext == nil) {
myManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType];
NSPersistentStoreCoordinator *psc = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
[myManagedObjectContext setPersistentStoreCoordinator:psc];
}
return myManagedObjectContext;
}

93sauu
- 3,770
- 3
- 27
- 43