UICollectionViewDiffableDataSourceReference
The object you use to manage data and provide cells for a collection view.
Declaration
@MainActor class UICollectionViewDiffableDataSourceReferenceOverview
A diffable data source object is a specialized type of data source that works together with your collection view object. It provides the behavior you need to manage updates to your collection view’s data and UI in a simple, efficient way. It also conforms to the UICollectionViewDataSource protocol and provides implementations for all of the protocol’s methods.
To fill a collection view with data:
Connect a diffable data source to your collection view.
Implement a cell provider to configure your collection view’s cells.
Generate the current state of the data.
Display the data in the UI.
To connect a diffable data source to a collection view, you create the diffable data source using its init(collectionView:cellProvider:) initializer, passing in the collection view you want to associate with that data source. You also pass in a cell provider, where you configure each of your cells to determine how to display your data in the UI.
self.dataSource = [[UICollectionViewDiffableDataSource alloc] initWithCollectionView:self.collectionView cellProvider:^UICollectionViewCell *(UICollectionView *collectionView, NSIndexPath *indexPath, id item) {
// Configure and return cell.
}];Then, you generate the current state of the data and display the data in the UI by constructing and applying a snapshot. For more information, see NSDiffableDataSourceSnapshotReference.
Topics
Creating a diffable data source
Creating supplementary views
Identifying items
Identifying sections
Updating data
snapshot()applySnapshot(_:animatingDifferences:)applySnapshot(_:animatingDifferences:completion:)applySnapshot(usingReloadData:)applySnapshot(usingReloadData:completion:)
Updating section data
snapshot(forSection:)applySnapshot(_:toSection:animatingDifferences:completion:)applySnapshot(_:toSection:animatingDifferences:)