onmyway133 / notes

:notebook_with_decorative_cover: Issues and solutions I found during development, mostly iOS
https://onmyway133.com/
MIT License
62 stars 4 forks source link

RxSwift #273

Open onmyway133 opened 7 years ago

onmyway133 commented 7 years ago
onmyway133 commented 7 years ago

Handle error

button.rx.tap
      .flatMapLatest({
        return Observable.error(AppError.cancelled)
          .flatMapLatest({
            return Observable.error(AppError.deallocated)
          })
          .catchErrorJustReturn(())
      })
      .flatMapLatest({
        return Observable.error(AppError.unknown).catchErrorJustReturn(())
      })
      .catchError({ error in
        print(error)
        return Observable.just(())
      })
      .map({
        return "hello"
      })
      .asDriver(onErrorRecover: { error in
        print(error)
        return Driver.just("hi")
      })
      .drive(onNext: { value in
        print(value)
      })