DiffableDataSource
-
The
DiffableDataSource.CollectionViewAdapterserves as aNSCollectionViewDataSourcethat handlesListPublishersnapshots for aNSCollectionView. Subclasses ofDiffableDataSource.CollectionViewAdaptermay override someNSCollectionViewDataSourcemethods as needed. TheDiffableDataSource.CollectionViewAdapterinstance needs to be held on (retained) for as long as theNSCollectionView‘s lifecycle.self.dataSource = DiffableDataSource.CollectionViewAdapter<Person>( collectionView: self.collectionView, dataStack: CoreStoreDefaults.dataStack, itemProvider: { (collectionView, indexPath, person) in let item = collectionView.makeItem(withIdentifier: .collectionViewItem, for: indexPath) as! PersonItem item.setPerson(person) return item } )The dataSource can then apply changes from a
ListPublisheras shown:listPublisher.addObserver(self) { [weak self] (listPublisher) in self?.dataSource?.apply( listPublisher.snapshot, animatingDifferences: true ) }DiffableDataSource.CollectionViewAdapterfully handles the reload animations.See moreSee also
CoreStore’s DiffableDataSource implementation is based on https://github.com/ra1028/DiffableDataSources
View on GitHub
DiffableDataSource Extension Reference