NSMergeByPropertyObjectTrumpMergePolicy vs. NSMergeByPropertyStoreTrumpMergePolicy

In my multi-threaded application, the main thread and one or more background threads can simultaneously receive, retrieve, and modify information in my main data store. For each thread, I create a new NSManagedObjectContext . However, each instance of NSManagedObjectContext uses the same instance of "NSPersistentStoreCoordinator" (stored elsewhere in singleton mode).

My question is about the merge policy of each instance of NSManagedObjectContext . Is there any internal benefit if I set one merge policy for background threads ( NSMergeByPropertyStoreTrumpMergePolicy ) and another policy ( NSMergeByPropertyObjectTrumpMergePolicy ) for the main thread?

In my NSMangagedObjectContext getter, I have the following condition:

  if ( [NSThread isMainThread] ) { [_context setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; } else { [_context setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy]; } 

Thanks.

Edit: is it necessary? Should I just by default use one policy over another for both types of threads?

+7
source share
2 answers

I ended up working with this solution (more than a year ago), but since I have not received an answer to this question recently, I decided to leave my own.

 NSManagedObjectContext *context; if ( [NSThread isMainThread] ) { context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; [context setMergePolicy:NSMergeByPropertyObjectTrumpMergePolicy]; } else { context = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType]; [context setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy]; } 
+3
source
0
source

All Articles