Created
May 30, 2018 10:07
-
-
Save bobgodwinx/f0c1298827ad7117badfd434ffa7ec50 to your computer and use it in GitHub Desktop.
S4D07
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
| /// `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