TableViewAdapter
open class TableViewAdapter<O> : BaseAdapter<O, DefaultTableViewTarget<UITableView>>, UITableViewDataSource where O : DynamicObject
The DiffableDataSource.TableViewAdapterAdapter serves as a UITableViewDataSource that handles ListPublisher snapshots for a UITableView. Subclasses of DiffableDataSource.TableViewAdapter may override some UITableViewDataSource methods as needed.
The DiffableDataSource.TableViewAdapterAdapter instance needs to be held on (retained) for as long as the UITableView‘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 ListPublisher as shown:
listPublisher.addObserver(self) { [weak self] (listPublisher) in
self?.dataSource?.apply(
listPublisher.snapshot,
animatingDifferences: true
)
}
DiffableDataSource.TableViewAdapter fully handles the reload animations.
See also
CoreStore’s DiffableDataSource implementation is based on https://github.com/ra1028/DiffableDataSources-
Initializes the
DiffableDataSource.TableViewAdapter. This instance 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 } )Declaration
Swift
public init( tableView: UITableView, dataStack: DataStack, cellProvider: @escaping (UITableView, IndexPath, O) -> UITableViewCell? )Parameters
tableViewthe
UITableViewto set thedataSourceof. This instance is not retained by theDiffableDataSource.TableViewAdapter.dataStackthe
DataStackinstance that the dataSource will fetch objects fromcellProvidera closure that configures and returns the
UITableViewCellfor the object -
The target
UITableViewDeclaration
Swift
public var tableView: UITableView? { get }
View on GitHub
TableViewAdapter Class Reference