I'm new in RxSwift, I don't understand what is difference between do(onNext:)
and subscribe(onNext:)
.
I google it but did't found good resources to explain the difference.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With