what is difference between do(onNext:) and subscribe(onNext:)?

At the beginning of a cold Observable chain there is a function that generates events, for e.g. the function that initiates a network request.

That generator function will not be called unless the Observable is subscribed to (and by default, it will be called each time the observable is subscribed to.) So if you add a do(onNext:) to your observable chain, the function will not be called and the action that generates events will not be initiated. You have to add a subscribe(onNext:) for that to happen.

(The actual internals are a bit more complex than the above description, but close enough for this explanation.)

Tags:

Rx Swift