UICollectionViewDiffableDataSource
does an excellent job of handling changes to data and updating the items accordingly. However, there seems to be no good way to handle updates to existing items. If you follow the samples that Apple provides and define Equatable
and Hashable
to use an id instead of the complete models value, value changes won't cause the collection view to update those cells. If you leave Equatable
as it should be and have it compare all values of a model, the cell will update, but it will completely replace the old cell, causing an undesirable "flash".
UICollectionViewComparableDataSource
wraps a UICollectionViewDiffableDataSource
and will check for items that have been updated, but not removed or added.
This allows us to make updates to a cell without completely reloading it. This is especially usefull if your cells have some sort of temporary state.
This is just an expirement. Use at your own risk.