In case anybody's interested, here's my implementation. I have an app with a list of games. Depending if the game is finished or still on going i use different cells. Here's my code:
In the ViewModel, I have a list of game, split them into finished/ongoing ones and map them to SectionModel
let gameSections = PublishSubject<[SectionModel<String, Game>]>()
let dataSource = RxTableViewSectionedReloadDataSource<SectionModel<String, Game>>()
...
self.games.asObservable().map {[weak self] (games: [Game]) -> [SectionModel<String, Game>] in
guard let safeSelf = self else {return []}
safeSelf.ongoingGames = games.filter({$0.status != .finished})
safeSelf.finishedGames = games.filter({$0.status == .finished})
return [SectionModel(model: "Ongoing", items: safeSelf.ongoingGames), SectionModel(model: "Finished", items: safeSelf.finishedGames)]
}.bindTo(gameSections).addDisposableTo(bag)
Then in the ViewController, I bind my sections to my tableview, and use different cells like this. Note that I could use the indexPath to get the right cell instead of the status.
vm.gameSections.asObservable().bindTo(tableView.rx.items(dataSource: vm.dataSource)).addDisposableTo(bag)
vm.dataSource.configureCell = {[weak self] (datasource, tableview, indexpath, item) -> UITableViewCell in
if item.status == .finished {
let cell = tableview.dequeueReusableCell(withIdentifier: "FinishedGameCell", for: indexpath) as! FinishedGameCell
cell.nameLabel.text = item.opponent.shortName
return cell
} else {
let cell = tableview.dequeueReusableCell(withIdentifier: "OnGoingGameCell", for: indexpath) as! OnGoingGameCell
cell.titleLabel.text = item.opponent.shortName
return cell
}
}