Note that there are some explanatory texts on larger screens.

plurals
  1. PONSRangeException exception in NSFetchedResultsChangeUpdate event of NSFetchedResultsController
    text
    copied!<p>I have a <code>UITableView</code> that uses an <code>NSFetchedResultsController</code> as data source.</p> <p>The core data store is updated in multiple background threads running in parallel (each thread using it's own <code>NSManagedObjectContext</code>).</p> <p>The main thread observes the <code>NSManagedObjectContextDidSaveNotification</code> notification and updates it's context with <code>mergeChangesFromContextDidSaveNotification:</code>.</p> <p>Sometimes it happens that the <code>NSFetchedResultsController</code> sends an <code>NSFetchedResultsChangeUpdate</code> event with an indexPath that does not exist anymore at that point.</p> <p>For example: The result set of the fetched results controller contains 1 section with 4 objects. The first object is deleted in one thread. The last object is updated in a different thread. Then sometimes the following happens:</p> <ul> <li>controllerWillChangeContent: is called.</li> <li>controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: is called with type = NSFetchedResultsChangeDelete, indexPath.row = 0.</li> <li>controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: is called with type = NSFetchedResultsChangeUpdate, indexPath.row = 3.</li> </ul> <p>But the fetched results controller contains only 3 objects now, and if call</p> <pre><code>MyManagedObject *obj = [controller objectAtIndexPath:indexPath] </code></pre> <p>to update the table view cell according to the <code>NSFetchedResultsChangeUpdate</code> event, this crashes with a <code>NSRangeException</code> exception.</p> <p>Thank you for any help or ideas!</p>
 

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