Created
December 7, 2018 11:47
-
-
Save shaktiprakash099/cb8cf638362fa4575a009108abb04c2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TableViewCustomDataSource<Model>: NSObject,UITableViewDataSource{ | |
typealias CellConfigurator = (Model,UITableViewCell)-> Void | |
var models:[Model] | |
private let reuseIdentifier:String | |
private let cellConfigurator: CellConfigurator | |
init(models:[Model],reuseIdentifier:String,cellConfigurator:@escaping CellConfigurator) { | |
self.models = models | |
self.reuseIdentifier = reuseIdentifier | |
self.cellConfigurator = cellConfigurator | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return models.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let model = models[indexPath.row] | |
let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) | |
cellConfigurator(model,cell) | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment