Note that there are some explanatory texts on larger screens.

plurals
  1. PONSFetchedResultsController not firing delegate method after merging update from background thread
    primarykey
    data
    text
    <p>I have an NSFetchedResultsController and a few operations that inserts and updates managed objects on separate threads via NSOperationQueue.</p> <p>The FRC looks like this, note that I have set the cache to nil:</p> <pre><code>[NSFetchedResultsController deleteCacheWithName:nil]; NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:nil cacheName:nil]; </code></pre> <p>Each threaded operation has its own managed object context and fires mergeChangesFromContextDidSaveNotification to the main MOC each time it saves changes.</p> <p>The code that I use to merge contexts looks like this:</p> <pre><code>- (void)mergeContextChanges:(NSNotification *)notification { NSManagedObjectContext *context = [fetchedResultsController managedObjectContext]; if([NSThread isMainThread] == NO) { [self performSelectorOnMainThread:_cmd withObject:notification waitUntilDone:NO]; return; } NSSet *updated = [[notification userInfo] objectForKey:NSUpdatedObjectsKey]; for(NSManagedObject *thing in updated) { NSLog(@"Background thread updated %@", [thing description]); } for(NSManagedObject *thing in updated) { [[context objectWithID:[thing objectID]] willAccessValueForKey:nil]; } [context mergeChangesFromContextDidSaveNotification:notification]; } </code></pre> <p>I can confirm by looking at the logs that each time the background operations insert or update data, my mergeContextChanges: method is being called with the proper insert/update values.</p> <p>The problem is that while merging <em>inserts</em> are firing the FRCs delegate methods (ex. controllerDidChangeContent:) properly, merging <em>updates</em> doesn't signal the FRC to fire its delegate methods.</p> <p>Strange enough, I can also confirm that the FRC fires its delegates properly if I run the updates on the <em>main thread</em> using the <em>main MOC</em>.</p> <p>How can I make the FRC fire its delegate methods when updated MOCs are merged?</p> <p><strong>More Info:</strong> Looks like using any MOC other than the main MOC and trying to merge <em>updates</em> to the main MOC has the same results; the FRC refuses to notice it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload