Note that there are some explanatory texts on larger screens.

plurals
  1. POManaged Object Removed from Fetched Results For No Reason
    primarykey
    data
    text
    <p>I've got an odd problem that I can't figure out. I have a fairly typical <code>UIViewController</code> with a <code>UITableView</code> and an <code>NSFetchedResultsController</code> fetching objects from an SQLite store. The fetching works fine and the table works fine, with typical <code>NSFetchedResultsController</code> boilerplate:</p> <pre><code>-(void)controllerWillChangeContent:(NSFetchedResultsController *)controller{ [self.tableView beginUpdates]; } -(void)controller:(NSFetchedResultsController *)controller didChangeSection:(id&lt;NSFetchedResultsSectionInfo&gt;)sectionInfo atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type{ if(type==NSFetchedResultsChangeInsert){ [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; } else if(type==NSFetchedResultsChangeDelete){ [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade]; } } -(void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath{ UITableView *tV = self.tableView; if(type==NSFetchedResultsChangeInsert){ [tV insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if(type==NSFetchedResultsChangeDelete){ [tV deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if(type==NSFetchedResultsChangeUpdate){ [self configureCell:[tV cellForRowAtIndexPath:indexPath] atIndexPath:indexPath]; } else if(type==NSFetchedResultsChangeMove){ [tV deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tV insertRowsAtIndexPaths:[NSArray arrayWithObject:newIndexPath] withRowAnimation:UITableViewRowAnimationFade]; } } -(void)controllerDidChangeContent:(NSFetchedResultsController *)controller{ [self.tableView endUpdates]; } </code></pre> <p>The problem I'm having is that objects with any relationships that are nil (even if the relationship property is not involved in the fetch request in either the predicate or sort descriptors) disappear from the fetched results (<code>controller:didChangeObject:</code> gets called with <code>NSFetchedResultsChangeDelete</code>) any time they are updated in any way (changing an unrelated property for instance). If I re-perform the fetch, the object will be back.</p> <p>This happens even if I don't use a predicate in the fetch request.</p> <p>Does anybody have any idea what might be going on here?</p>
    singulars
    1. This table or related slice is empty.
    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