I am using CoreData with multiple contexts (Not Parent-Child). So, I am using NSManagedObjectContextDidSaveNotification
observer to update the information in different contexts. One wired issue I am facing is when a saved data on a background thread is updated on the main thread using NSManagedObjectContextDidSaveNotification
then if in future I apply rollback on main thread context then it rolls back the updated info.
Can anyone explain why it is happening?
NSMergePolicy *policy = [[NSMergePolicy alloc] initWithMergeType:NSMergeByPropertyStoreTrumpMergePolicyType];
NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if ([NSThread isMainThread]) {// main thread context
if (!self.managedObjectContextMainThread) {
self.managedObjectContextMainThread = [[NSManagedObjectContext alloc] init];
[self.managedObjectContextMainThread setMergePolicy:policy];
[self.managedObjectContextMainThread setPersistentStoreCoordinator:coordinator];
}
}else{
context = [[NSManagedObjectContext alloc] init];
[context setPersistentStoreCoordinator:coordinator];
[context setMergePolicy:policy];
}