The catchErrorJustReturn operator

The catchErrorJustReturn operator recovers from an error event by returning an observable sequence that emits a single element and then terminates. We will create a PublishSubject that will emit an error, as follows:

example(for: "catchErrorJustReturn") {        let disposeBag = DisposeBag()    let pubSubject = PublishSubject<String>()        subject.catchErrorJustReturn("")}

Now we will subscribe and print out the emitted events. We will use the catchErrorJustReturn operator on it to return a smiley, as follows:

let disposeBag = DisposeBag()    let pubSubject = PublishSubject<String>()        pubSubject.catchErrorJustReturn("Demon Error")        .subscribe{ print($0) }        .disposed(by: disposeBag)

We will add a value to this subject, as ...

Get Reactive Programming with Swift 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.