init(collectionView:cellProvider:)
Creates a diffable data source with the specified cell provider, and connects it to the specified collection view.
Declaration
init(collectionView: UICollectionView, cellProvider: @escaping UICollectionViewDiffableDataSourceReferenceCellProvider)Parameters
- collectionView:
The initialized collection view object to connect to the diffable data source.
- cellProvider:
A closure that creates and returns each of the cells for the collection view from the data the diffable data source provides.
Discussion
To connect a diffable data source to a collection view, you create the diffable data source using this 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
}];