I am using two MOCs, one for the main thread, and another MOC on a background thread. On the main thread I have a UITableView working with an FRC (NSFetchedResultsController).
Once in a while I run a massive save operation, that deletes all objects and builds a few hundreds of new objects... At this point I want to UITableView in the main thread to refresh its data (using the FRC obviously). Therefore the main MOC registers to the NSManagedObjectContextDidSaveNotification notification (received from the background MOC) and runs mergeChangesFromContextDidSaveNotification at that stage to make sure the UITableView updates accordingly.
This all works fine until I try to scroll the UITableView during the save operation. When I try to scroll the view a "coredata could not fulfill a fault" exception is raised. This is the result of the FRC still holding objects that were already deleted (while the save operation still runs, before mergeChangesFromContextDidSaveNotification from NSManagedObjectContextDidSaveNotification notification is received on main MOC). This is some sort of a "race condition" between the save operation and the update of the UITableView after mergeChangesFromContextDidSaveNotification is received.
What is the right approach to work with those two MOCs and taking care of the FRC so it will be able to cope with this scenario?</div