O'Reilly logo

Reactive Programming with Swift 4 by Navdeep Singh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

doOn in action

Let's work with doOn in code. We will use the same playground page, and start by commenting out the implementation so far. We will create a bare-bones implementation of the method for doOn and inside the implementation we will declare a disposeBag, as follows:

executeProcedure(for: "do(on....:)") {         let disposeBag = DisposeBag()    }

Then, we will create a PublishSubject of the Int type:

let temperatureInFahrenheit = PublishSubject<Int>()

This PublishSubject will hold values that are temperatureInFahrenheit that we want to convert to Celsius.

We will chain a do(onNext:) operator on to the sequence and in it, multiply the element by itself. Although we could work with the result of this calculation within the do(onNext:) handler, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required