I'm struggling to understand how to use UICollectionViewDiffableDataSource
and NSDiffableDataSourceSnapshot
to model change of items.
Let's say I have a simple item which looks like this:
struct Item {
var id: Int
var name: String
}
Based on the names of the generic parameters, UICollectionViewDiffableDataSource
and NSDiffableDataSourceSnapshot
should operate not with Item
itself, but only with identifier, which Int
in this example.
On the other hand, again based on names of generic parameters, UICollectionView.CellRegistration
should operate on complete Item
's. So my guess is that UICollectionViewDiffableDataSource.CellProvider
is responsible for finding complete Item's
by id. Which is unfortunate, because then aside from snapshots, I need to maintain a separate storage of items. And there is a risk that this storage may go out of sync with snapshots.
But it is still not clear to me how do I inform UICollectionViewDiffableDataSource
that some item changed its name
without changing its id
. I want UICollectionView
to update the relevant cell and animate change in content size, but I don't want insertion or removal animation.