DiffableDataSource
public enum DiffableDataSource
Namespace for diffable data source types. See DiffableDataSource.TableViewAdapter and DiffableDataSource.CollectionViewAdapter for actual implementations
-
The
DiffableDataSource.BaseAdapterserves as a superclass for consumers ofListPublisherandListSnapshotdiffable data.self.dataSource = DiffableDataSource.TableViewAdapter<Person>( tableView: self.tableView, dataStack: CoreStoreDefaults.dataStack, cellProvider: { (tableView, indexPath, person) in let cell = tableView.dequeueReusableCell(withIdentifier: "PersonCell") as! PersonCell cell.setPerson(person) return cell } )The dataSource can then apply changes from a
ListPublisheras shown:listPublisher.addObserver(self) { [weak self] (listPublisher) in self?.dataSource?.apply( listPublisher.snapshot, animatingDifferences: true ) }See moreSee also
CoreStore’s DiffableDataSource implementation is based on https://github.com/ra1028/DiffableDataSourcesDeclaration
Swift
open class BaseAdapter<O, T> : NSObject where O : DynamicObject, T : DiffableDataSourceTarget
-
The
DiffableDataSource.CollectionViewAdapterserves as aUICollectionViewDataSourcethat handlesListPublishersnapshots for aUICollectionView. Subclasses ofDiffableDataSource.CollectionViewAdaptermay override someUICollectionViewDataSourcemethods as needed. TheDiffableDataSource.CollectionViewAdapterinstance needs to be held on (retained) for as long as theUICollectionView‘s lifecycle.self.dataSource = DiffableDataSource.CollectionViewAdapter<Person>( collectionView: self.collectionView, dataStack: CoreStoreDefaults.dataStack, cellProvider: { (collectionView, indexPath, person) in let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "PersonCell") as! PersonCell cell.setPerson(person) return cell } )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/DiffableDataSourcesDeclaration
Swift
open class CollectionViewAdapter<O> : BaseAdapter<O, DefaultCollectionViewTarget<UICollectionView>>, UICollectionViewDataSource where O : DynamicObject
-
The
DiffableDataSource.TableViewAdapterAdapterserves as aUITableViewDataSourcethat handlesListPublishersnapshots for aUITableView. Subclasses ofDiffableDataSource.TableViewAdaptermay override someUITableViewDataSourcemethods as needed. TheDiffableDataSource.TableViewAdapterAdapterinstance needs to be held on (retained) for as long as theUITableView‘s lifecycle.self.dataSource = DiffableDataSource.TableViewAdapter<Person>( tableView: self.tableView, dataStack: CoreStoreDefaults.dataStack, cellProvider: { (tableView, indexPath, person) in let cell = tableView.dequeueReusableCell(withIdentifier: "PersonCell") as! PersonCell cell.setPerson(person) return cell } )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.TableViewAdapterfully handles the reload animations.See moreSee also
CoreStore’s DiffableDataSource implementation is based on https://github.com/ra1028/DiffableDataSourcesDeclaration
Swift
open class TableViewAdapter<O> : BaseAdapter<O, DefaultTableViewTarget<UITableView>>, UITableViewDataSource where O : DynamicObject
-
The
DiffableDataSource.Targetprotocol allows custom views to consumeListSnapshotdiffable data similar to howDiffableDataSource.TableViewAdapterandDiffableDataSource.CollectionViewAdapterreloads data for their corresponding views.Declaration
Swift
public typealias Target = DiffableDataSourceTarget
View on GitHub
DiffableDataSource Enumeration Reference