Below is a simple example of binding a string array of viewModel to UITableView.
I want to subscribe to one more viewModel.randomString and use it in the cell.
I tried using combineLatest as below, but of course I couldn't bind to tableview.
Do you have any ideas on how to implement it?
class SimpleViewModel {
var list = BehaviorRelay<[String]>(value: [])
var randomString = BehaviorRelay<String>(value: "")
func fetch() {
// Request...
list.accept(["result1", "result2", "result3"])
randomString.accept("Random...")
}
}
class SimpleViewController {
let tableView = UITableView()
let viewModel = ViewModel()
func foo() {
// It works well.
viewModel.list.bind(to: tableView.rx.items(cellIdentifier: "Cell")) { (index, element, cell) in
cell.textLabel?.text = element
}
// I want to bind the viewModel.list to the tableView and use the viewModel.randomString string together.
Observable.combineLatest(viewModel.list, viewModel.randomString)
// How???
// .bind(to: tableView.rx.items(cellIdentifier: "Cell")) { (index, element, cell) in
// cell.textLabel?.text = element + "RandomString" // I want to use the "RandomString" of viewModel.randomString
// }
}
}