You may miss the savings on the MOC chain. For clarity, I replaced the private keyword with the variable name backgroundMOC .
In the above question, I can only assume that the line NSManagedObjectContext *private = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; technically similar:
- (NSManagedObjectContext *)backgroundMOC:(NSManagedObjectContext *)mainMOC { NSManagedObjectContext * threadManagedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [threadManagedObjectContext setParentContext:mainMOC]; [threadManagedObjectContext setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; return threadManagedObjectContext; }
passes self.model.context as mainMOC, with self.model.context and a setMergePolicy .
Similarly, I have to assume that self.model saveWithErrorBlock technically identical:
[mainMOC performBlockAndWait:^{ if([mainMOC hasChanges]) { NSError * error; [mainMOC save:&error];
If yes, then the same should be said about backgroundMOC (your link is private ):
[backgroundMOC performBlockAndWait:^{ if([backgroundMOC hasChanges]) { NSError * error; [backgroundMOC save:&error];
In other words, you want your backgroundMOC and mainMOC save operations to mainMOC performed from their respective threads using performBlockAndWait .
source share