A little late answer, but maybe it will be useful for those who do it.
You can configure the NSFetchedResultsController
for the child with the predicate @"parent == %@", child
, and then add the controller as a delegate for this fetchedResultController. The delegate will be called when any of the child’s properties changes, as well as when they are added, etc. The following is sample code. I also added a sort descriptor to sort children by their name on
... NSFetchRequest* fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Child"]; fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES]]; NSPredicate* predicate = [NSPredicate predicateWithFormat:@"parent = %@", parent]; self.fetchResultsController.fetchRequest.predicate = predicate; self.fetchResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:context sectionNameKeyPath:nil cacheName:nil]; self.fetchResultsController.delegate = self; ...
Then you implement the delegate method
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type newIndexPath:(NSIndexPath *)newIndexPath {
And any other delegate method you need for your implementation (the documentation has a very nice piece of code for this
source share