Selecting a row in TableView

Instead of implementing didSelectRowAtIndexPath(), we will implement rx.modelSelected of tableView, which takes the type of dataModel, Developer in this case, and it emits a nextEvent containing the selected element property type that we can subscribe to and then print out the selected developer, as shown:

demoTableView.rx.modelSelected(Developer.self)            .subscribe(onNext: {                print("Selected Develoer:", $0)            })            .disposed(by: disposeBag)

This refractor has reduced the lines of code by at least 25%, and running the app again will produce the same result as earlier.

There are extensions for most of the delegate and dataSource methods in RxCocoa and matching extensions for UICollectionViews. So we encourage you to check ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.