-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathArrayDataSource.swift
40 lines (29 loc) · 1004 Bytes
/
ArrayDataSource.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
// ArrayDataSource.swift
// Westeros
//
// Created by yisus on 18/07/2017.
// Copyright © 2017 yisus. All rights reserved.
//
import UIKit
final class ArrayDataSource <Element> : NSObject , UITableViewDataSource {
typealias Elements = [Element]
typealias CellMaker = (Element,UITableView) -> UITableViewCell
private let _models: Elements
private let _cellMaker: CellMaker
init (model: Elements,cellMaker: @escaping CellMaker) {
_models = model
_cellMaker = cellMaker
super.init()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return _models.count
}
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let elt = _models[indexPath.row]
return _cellMaker(elt,tableView)
}
}