CoreData, @FetchRequest, @ObservedObject and View Updating

I am having an issue in all my apps in which the list view is not updating when the detail view data is changed. All of these views follow the same basic format, with environment variables injected as instructed. The basic form is:

ListView with @FetchRequest returning “items” inside a NavigationView.
DetailView with @ObservedObject “item”
DetailView2 with @ObservedObject.

All the views have the same moc environment variable, but more often than not, the ListView is not updating to reflect changes from the detail view, such as adding a photo or changing the title. How can I make this work more effectively?

Thanks.

fwiw, my experiences with DiffableDataSources and CoreData is that they are great at detecting additions and deletions (because the managed object IDs in the fetched results are different) but don't work for updates (because the ids stay the same, only the properties change). I thought I saw a very brief comment in a video about updating DiffableDataSources due to property changes, but damn if I can remember which video that was.

also fwiw, in UIKit, I solve for this by observing the changed records of the FetchedRsultsController, and specifically reloading them in the diffable data source.

    …

    func updateSnapshot() {
        var diffableDataSourceSnapshot = NSDiffableDataSourceSnapshot<String, Car>()
        frc.sections?.forEach { section in
            diffableDataSourceSnapshot.appendSections([section.name])
            diffableDataSourceSnapshot.appendItems(section.objects as! [Car], toSection: section.name)
        }
        diffableDataSourceSnapshot.reloadItems(changedCars)
        
        diffableDataSource?.apply(diffableDataSourceSnapshot, animatingDifferences: true)
    }
    
}

extension CarsListViewController: NSFetchedResultsControllerDelegate {
    
    func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
        
        if type == .update, let car = anObject as? Car {
            changedCars.append(car)
        }
    }
    
    func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
        self.updateSnapshot()

        changedCars.removeAll()
    }

}

Note this means I am not using the fancy new FRC delegate callbacks with snapshots, because they only have adds/deletes, no updates.

CoreData, @FetchRequest, @ObservedObject and View Updating
 
 
Q