Skip to content

Instantly share code, notes, and snippets.

@bobgodwinx
Created May 30, 2018 10:07
Show Gist options
  • Select an option

  • Save bobgodwinx/f0c1298827ad7117badfd434ffa7ec50 to your computer and use it in GitHub Desktop.

Select an option

Save bobgodwinx/f0c1298827ad7117badfd434ffa7ec50 to your computer and use it in GitHub Desktop.
S4D07
/// `ContactViewController` = `View`
class ContactViewController: UIViewController {
private let bag = DisposeBag()
let viewModel: Contactable
/// `dependency inversion`
init(_ viewModel: Contactable) {
self.viewModel = viewModel
super.init(nibName: nil, bundle: nil)
configure()
}
required init?(coder aDecoder: NSCoder) { fatalError("Please initialise programmatically") }
private func configure() {
let tableView = UITableView(frame: CGRect(x: 0, y: 0, width: 768, height: 1024), style: .plain)
tableView.register(PersonCell.self, forCellReuseIdentifier: PersonRow.cellIdentifier)
/// Here goes the magical binding
viewModel
.datasource
.drive(tableView.rx.items(dataSource: TableDatasource()))
.disposed(by: bag)
/// Adding the `UITableView` as subview
view.addSubview(tableView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment