Reputation: 133
I have a problem with implementing a UITableView using RxSwift.
I tried to bind an observable of an array of models to the table items with the following code.
models.bind(to: self.tableView.rx.items(cellIdentifier: "Cell", cellType: ModelTableViewCell.self
.
But when I do it gives me the following error: Type 'inout UITableView' does not conform to protocol 'ReactiveCompatible'
and I know the error can't be right because NSObject extends ReactiveCompatible so UITableView also does. Also, my project code isn't really different than the examples shown on RxSwiftCommunity
I created a small example project that has the error.
Upvotes: 4
Views: 4440
Reputation: 1570
Swift is quite good language but sometimes happens moments when compiler couldn't recognize the type of parameters. Then you need to explicit define a type of arguments. In your case you need to define the type of block arguments, see the code:
func bindRx(viewModel: ViewModel) {
viewModel.models.bind(to: tableView.rx.items(cellIdentifier: ModelTableViewCell.ReuseIdentifier,
cellType: ModelTableViewCell.self)) { (_, model: Model, cell: ModelTableViewCell) in
cell.textLabel?.text = model.name
}
.addDisposableTo(disposeBag)
}
Upvotes: 7