Join Scott Gardner for an in-depth discussion in this video Perform side effects, part of Reactive Programming in iOS with RxSwift.
- [Voiceover] As you saw in the Darts…scoring example earlier,…sometimes when you're working with…an observable sequence, you want to perform some action,…or a side effect, when elements are emitted,…that won't change anything specifically…about the elements emitted.…You can use the doOn operator,…to perform side effects,…and there are convenience operators,…including doOn next, doOn error, and doOn completed too.…Think of doOn, as a wire tap on an observable sequence.…You can listen in, but not modify the elements,…and doOn, will pass through each event.…
You might use doOn to do logging, for example.…So let's say I have an array of temperatures,…that are in degrees Fahrenheit.…When I chain a doOn, or a doOn next operator,…as I've done here,…I can work with the emitted element,…but anything I do in the handler,…will not modify the element.…Instead, it will just pass the original element through,…after executing the code in the handler.…So, unlike if we were using map,…multiplying the number by itself here, does nothing.…
Learn reactive programming with Reactive Extensions for Swift and iOS by following along with author Scott Gardner. Scott introduces the Reactive Extensions libraries for Swift and Cocoa Touch, and shows how to work with observable sequences, bind user interface and data elements, perform networking operations, debug Rx code, and more.
- Using the Reactive Extensions library
- Working with observable sequences
- Binding UI and data elements
- Binding table and collection views
- Error handling