Search code examples
ioscore-datansfetchedresultscontroller

How to make NSFetchedResultsController be notified if related object changed


I have very simple structure relations

FeedItem - root object, it's has object post.

"FeedItem"
{
 "post" : 
      {"id" : 1, "name" : "Test"}
}

I made NSFetchedResultsController to a FeedItem, but in one case i make changes in post object.

I wonder, if it's possible to make NSFetchedResultsController trigger when changed related object?

I found solution via

[[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(refreshData:)
                                                     name:NSManagedObjectContextObjectsDidChangeNotification
                                                   object:nil];

But in this case i need manually check if there in notification has my objects, because it's contains all objects which be updated, added, deleted.


Solution

  • The FRC only tracks changes in the feed items, not the items related to them. If you want to trigger a change then you need to make a change, like removing and re-adding the relation, so the feed item is dirty and will be saved.

    Your notification is an acceptable alternative which is cleaner and makes the intention clear.