Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- protocol SourceType: UITableViewDataSource {
- associatedtype Element
- var dataObject: Element { get set }
- }
- class DataSource<T: DataType>: NSObject, SourceType {
- typealias Element = T
- var dataObject: Element
- init(dataObject: Element) {
- self.dataObject = dataObject
- }
- @objc func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return dataObject.numberOfItems
- }
- @objc func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- fatalError("this method must be override")
- }
- }
- protocol DataType {
- var numberOfItems: Int { get }
- }
- final class CustomDatasource: DataSource<List> {
- override init(dataObject: List) {
- super.init(dataObject: dataObject)
- }
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- return UITableViewCell()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement