Step into Swift logo

What is the SwitchLatest Operator in RxSwift?

SwitchLatest Operator

RxSwift: SwitchLatest Operator

.switchLatest { }

  • Emits values from the most recent Observable and the unsubscribes from the previous emitting Observable.
  • Unsubscribes from previous Observable when a new Observable is emitted from the source Observable, not when the new Observable emits an element. (i.e. The last X below will not be emitted.)
-------------------------------->
---X----X-X---X----------------->
|||||||||||||---Y------Y-----Y-->

`switchLatest`

---X----X-X-----Y------Y-----Y-->

< All Posts