Skip to content

Instantly share code, notes, and snippets.

@thiagolioy
Created November 21, 2016 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thiagolioy/d9828f635f06c6a2dcc1fad4a3e2418a to your computer and use it in GitHub Desktop.
Save thiagolioy/d9828f635f06c6a2dcc1fad4a3e2418a to your computer and use it in GitHub Desktop.
final class CharactersDatasource: NSObject, ItemsTableViewDatasource {
var items:[Character] = []
weak var tableView: UITableView?
weak var delegate: UITableViewDelegate?
required init(items: [Character], tableView: UITableView, delegate: UITableViewDelegate) {
self.items = items
self.tableView = tableView
self.delegate = delegate
super.init()
tableView.register(cellType: CharacterTableCell.self)
self.setupTableView()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: CharacterTableCell.self)
let character = self.items[indexPath.row]
cell.setup(item: character)
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment