Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class DataSource<T>: NSObject, UITableViewDataSource {
- var items: [T] {
- didSet {
- self.tableView?.reloadData()
- }
- }
- weak var tableView: UITableView?
- var fill: (UITableViewCell, T) -> UITableViewCell
- var identifier: String
- init(fill tableView: UITableView, with items: [T], identifier: String, fill: @escaping (UITableViewCell, T) -> UITableViewCell) {
- self.items = items
- self.tableView = tableView
- self.identifier = identifier
- self.fill = fill
- }
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return items.count
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- var cell = tableView.dequeueReusableCell(withIdentifier: identifier)!
- cell = fill(cell, items[indexPath.row])
- return cell
- }
- }
Add Comment
Please, Sign In to add comment