You're already observing the managed object context for changes, but they are only processed if the family member that is shown on the current page has updated. This logic should be replaced so that it will reload the table view if either the family member or their favorite movies change. Update the managedObjectContextDidChange(_:) method in MoviesViewController.swift as follows:
@objc func managedObjectContextDidChange(notification: NSNotification) { guard let userInfo = notification.userInfo else { return } if let updatedObjects = userInfo[NSUpdatedObjectsKey] as? Set<FamilyMember>, let familyMember = self.familyMember, updatedObjects.contains(familyMember) { tableView.reloadData() } if let updatedObjects = userInfo[NSUpdatedObjectsKey] as? Set<Movie> { for object in updatedObjects { if object.familyMember == familyMember { tableView.reloadData() break } } } }
It's important that the loop in the second if statement is set up like this because you might have just added a movie for family member A and then switched to family member B while the new movie for family member A is still loading its rating. Also, breaking out of the loop early ensures that you don't loop over any more objects than needed. All you want to do is refresh the table view if one of the current family members' favorite movies is updated.
Okay, build and run your app to take it for a spin! You'll notice that everything works as you'd want it to right now. Adding new movies triggers a network request; as soon as it finishes, the UI is updated with the new rating. Sometimes, this update will be done in an instant, but it could take a short while if you have a slow internet connection. Great! That's it for this feature.