Вам необходимо создать класс, соответствующий UITableViewDataSource, а также Observer.Быстрая и грязная версия будет выглядеть примерно так:
class DataSource: NSObject, UITableViewDataSource, ObserverType {
init(tableView: UITableView) {
self.tableView = tableView
super.init()
tableView.dataSource = self
}
func on(_ event: Event<[MyData]>) {
switch event {
case .next(let newData):
data = newData
tableView.reloadData()
case .error(let error):
print("there was an error: \(error)")
case .completed:
data = []
tableView.reloadData()
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let item = data[indexPath.row]
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
// configure cell with item
return cell
}
let tableView: UITableView
var data: [MyData] = []
}
Создайте экземпляр этого класса как свойство вашего контроллера представления.Свяжите свой myData
с ним следующим образом:
self.myDataSource = DataSource(tableView: self.tableView)
self.myData
.bind(to: self.myDataSource)
.disposed(by: self.bag)
(я поставил все self
в приведенном выше, чтобы сделать вещи явными.)
Вы можете уточнить это до такой степени, чтовы эффективно повторно реализуете источник данных RxCoca, но какой в этом смысл?