Join Scott Gardner for an in-depth discussion in this video Error handling: Part 2, part of Reactive Programming in iOS with RxSwift.
- [Voiceover] I'll copy and paste the code…from the last example,…and change the conditional logic…to allow repetitive retries.…I'll change the retry operator…to retry(maxAttemptCount) instead.…And now you can see that it retries three times…and ultimately fails and thus prints out the error event.…As I've mentioned, drivers guarantee not to fail,…that is, terminate with an error event.…Some uses of drivers can preemptively determine…what to return in case an error does occur.…
Similar to regular observable sequences,…drivers can just return a sequence that emits…a single element and terminates.…I'll create a PublishSubject.…And then when I want to use it as a driver,…I'll see there are three options in the code completion.…I'll select (onErrorJustReturn) and return the value 1000.…Now I'll use driveNext…and print out the elements as they're emitted.…Next, I'll add a couple values onto the subject sequence.…
And they're emitted.…Now I'll add an error onto the subject…and see that the return value 1000 is emitted.…
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