Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rx_itemsWithCellFactory call syntax

In RxSwift example this works:

        viewModel.rows
        .bindTo(resultsTableView.rx_itemsWithCellIdentifier("WikipediaSearchCell")) { (_, viewModel, cell: WikipediaSearchCell) in
            cell.viewModel = viewModel
        }
        .addDisposableTo(disposeBag)

How to write it using rx_itemsWithCellFactory?

like image 540
Vladimir Borodko Avatar asked Jan 08 '23 10:01

Vladimir Borodko


1 Answers

It took me a while to get it, and no help from google yet. I hope it'll save you few minutes

        viewModel.rows
        .bindTo(resultsTableView.rx_itemsWithCellFactory){
            (tv, i, vm) in
            let indexPath = NSIndexPath(forItem: i, inSection: 0)
            let cell = tv.dequeueReusableCellWithIdentifier("WikipediaSearchCell", forIndexPath: indexPath) as! WikipediaSearchCell
            cell.viewModel = vm
            return cell as UITableViewCell
        }
        .addDisposableTo(disposeBag)
like image 188
Vladimir Borodko Avatar answered Jan 10 '23 00:01

Vladimir Borodko