take this workflow as an example:
NSFetchedResultsController is binded to Main MOC, but Main MOC doesn't do the real save thing, it will propagate to Background Writer MOC, when the latter save to PSC, how can NSFetchedResultsController be notified?
i make a demo to test this, it works, but can't figure out why it works?
Main MOC does not get notified when the data is saved to the persistence store.
However, the only way the data should end up in the background writer MOC is through the temporary background MOC, which goes through the UI MOC. So NSFetchedResultsController
gets notified whenever temporary background MOC propagates it data upwards to the UI MOC, and then a separate thread saves it to PSC.
Data is not actually in the sqlite database when NSFetchedResultsController
gets notified but it does not have to be.
It is also evident from your save method:
- (void)save
{
[self.mainContext performBlock:^{
NSError *mainContextError;
if(![self.mainContext save:&mainContextError]) {
NSLog(@"main context error:%@", mainContextError);
}
[self.masterContext performBlock:^{
NSLog(@"saving in masterContext");
NSError *masterContextError;
if (![self.masterContext save:&masterContextError]) {
NSLog(@"master context error:%@", masterContextError);
}
}];
}];
}
after [self.mainContext save]
is called, NSFetchedResultsController
will get notified.