I ran into NSFetchedResultsController issue developing guest-management application.
The application basically downloads list of guests on background (using NSOperation subclass), inserts them to managed object context and then presents them in table view on UI thread.
I think that I am following the core data multi-threading rules (I have separate MOC for the operation created on its thread, I synchronize my main MOC using did-save notification etc.).
What I do not fully understand is the behavior of NSFetchedResultsController which seems to be calling its delegate methods (controllerDidChangeContent etc.) at background thread instead of main thread which leads to illegal UI updates.
So my question is – is it legal to use NSFetchedResultsControllerDelegate to observe changes that come from MOC did save notification or is NSFetchedResultsControllerDelegate designed to work only with changes done on the main thread?
I’m not sure if my explanation is clear enough, if not I can post some code to demonstrate the problem.
My guess is that your MOC did-save notification is being sent and observed on the background thread instead of the main event thread. This would cause the
NSFetchedResultsControllerDelegateto send delegate messages on the background thread.You need to make sure your did-save notification observer passes control to the main thread, e.g: