1
votes

If I have one NSManagedObjectContext and two children of it, one for updating in background from web service (A) and other for operations in the UI thread (B) the question is: How the NSManagedObjectContext B is notified about changes in the parent managed object context once the background context (A) has been updated with new information and save it to the parent context?

Thanks

1

1 Answers

5
votes

If I understand right, you can observe the DidSaveNotification from you context B. Like this:

self.observer = [[NSNotificationCenter defaultCenter] addObserverForName:NSManagedObjectContextDidSaveNotification object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *note) {
    NSManagedObjectContext *notMoc = [note object];
    if (![weakSelf.managedObjectContext isEqual:notMoc]) {
        [weakSelf.managedObjectContext performBlock:^{
            [weakSelf.managedObjectContext mergeChangesFromContextDidSaveNotification:note];
        }];
    }
}];