Update cell content - UITableView Diffable DataSource
So I'm implementing the Diffable Data Source API for a UITableView, I have a trailing swipe action mark as favorite the item that you swiped; what is the correct approach using this API, re-render my Custom Cell so it's "Favorite Star Image" is activated, currently it's only updated when you segue to another view and come back. I have two methods that are used by the diffable data source: updateUI(), setupFetchedResults().
// Swipe handler:
let favoriteAction = UIContextualAction(style: .normal, title: "Favorite") { [weak self] _, _, completionHandler in
account.favorite.toggle()
self?.updateUI()
completionHandler(true)
}
// My updateUI method:
private func updateUI(animated: Bool = true){
diffableDataSourceSnapshot = NSDiffableDataSourceSnapshot<DiffableSection, Account>()
diffableDataSourceSnapshot.appendSections([.main])
diffableDataSourceSnapshot.appendItems(fetchedResultsController.fetchedObjects ?? [])
dataSource?.apply(diffableDataSourceSnapshot, animatingDifferences: animated)
}