Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created November 27, 2017 20:41
Show Gist options
  • Save azamsharp/4f4cbcf3d2c0f03f35cafdb8f610e15f to your computer and use it in GitHub Desktop.
Save azamsharp/4f4cbcf3d2c0f03f35cafdb8f610e15f to your computer and use it in GitHub Desktop.
TableViewDataSource in SourcesTableViewController
class SourcesTableViewController : UITableViewController {
private var webservice :Webservice!
private var sourceListViewModel :SourceListViewModel!
private var dataSource :TableViewDataSource<SourceTableViewCell,SourceViewModel>!
override func viewDidLoad() {
super.viewDidLoad()
updateUI()
}
private func updateUI() {
self.webservice = Webservice()
self.sourceListViewModel = SourceListViewModel(webservice: self.webservice)
// setting up the bindings
self.sourceListViewModel.bindToSourceViewModels = {
self.updateDataSource()
}
}
private func updateDataSource() {
self.dataSource = TableViewDataSource(cellIdentifier: Cells.source, items: self.sourceListViewModel.sourceViewModels) { cell, vm in
cell.nameLabel.text = vm.name
cell.descriptionLabel.text = vm.body
}
self.tableView.dataSource = self.dataSource
self.tableView.reloadData()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment