Created
November 27, 2017 20:41
-
-
Save azamsharp/4f4cbcf3d2c0f03f35cafdb8f610e15f to your computer and use it in GitHub Desktop.
TableViewDataSource in SourcesTableViewController
This file contains hidden or 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
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