Search code examples
iosuitableviewcore-datansfetchedresultscontroller

How to know which property is changed for NSFetchedResultsChangeUpdate?


I thinks there is a problem of controller:didChangeObject:atIndexPath:forChangeType:newIndexPath:, specifically for NSFetchedResultsChangeUpdate: It does not tell you what change causes this NSFetchedResultsChangeUpdate.

I have a very complex entity. Only a part of its data is are used to populate my table view cells. I don't want to update my cells for any irrelevant property changes — it is a waste of resources. So how can I know which property change causes this NSFetchedResultsChangeUpdate so that I can avoid updating my table view cells if it is irrelevant?


Solution

  • NSManagedObject have two methods for that. First returns a dictionary with the keys and (new) values that have been changed since last fetching or saving the object (this is implemented efficiently without firing relationship faults)

    - (NSDictionary *)changedValues;
    

    Second:

    - (NSDictionary *)changedValuesForCurrentEvent NS_AVAILABLE(10_7, 5_0);
    

    You call their on NSFetchedResultsChangeUpdate notification by NSFetchedResultsController