Provides an abstraction layer to deal with listable data. It's a simpler and faster way to build table views on top of this than from scratch.
Item for cells must adopt Hashable
protocol.
Table view cell should conform to Configurable
protocol in order to receive cell item for setup.
extension Cell: Configurable {
public func setup(with item: User) {
textLabel?.text = item.name
}
}
Sometimes you need to set delegate for cell, header or footer. For that purpose table adapter has sender
property, which will be passed to configurable view, that adopts SenderConfigurable
protocol.
extension Cell: SenderConfigurable {
func setup(with item: Item, sender: ViewController) {
textLabel?.text = object.name
delegate = sender
}
}
You must provide tableView
property.
class ExamplesViewController: TableController<Int, Example> {
override var tableView: UITableView { examplesTableView }
private let examplesTableView = UITableView(frame: .zero, style: .grouped)
private let items: [Example] = [ ... ]
override func viewDidLoad() {
super.viewDidLoad()
// Setup table
view.addSubview(tableView)
tableView.register(ExampleCell.self, forCellReuseIdentifier: defaultCellReuseIdentifier)
apply(items: items)
}
func apply(items: [RowItem], animated: Bool = false) {
var snapshot = snapshot
snapshot.deleteAllItems()
snapshot.appendSections([0])
snapshot.appendItems(items, toSection: 0)
apply(snapshot, animating: animated)
}
}
- Swift 5.1+
- iOS 13.0+