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 ...