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?
ArtSabintsev
source share