Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RxSwift Intro

Avatar for CJ CJ
September 09, 2018
53

RxSwift Intro

Avatar for CJ

CJ

September 09, 2018
Tweet

Transcript

  1. Rx Introduction • Why Rx • Basic concepts • Creating

    Observables • Wrapping API call • Dispose bag • Operators • How to make concurrent / serial API calls using Rx
  2. Basic concepts • Observable is equivalent to Sequence • Sequence

    in Swift: 
 A type that provides sequential, 
 iterated access to its elements.
  3. Basic concepts • Observables and observers (aka subscribers) • Will

    not execute their subscription closure unless there is a subscriber. • next* (error | completed)?
  4. Dispose bag When a sequence sends the completed or error

    event all internal resources will be freed. To cancel production of sequence elements and free resources immediately, call dispose on the returned subscription. disposed(by: disposeBag) will automatically call dispose at deinit
  5. FlatMapLatest The flatMapLatest operator behaves much like the standard FlatMap

    operator, except that whenever a new item is emitted by the source Observable, it will unsubscribe the Observable that was generated from the previously-emitted item, and begin only mirroring the current one.
  6. FlatMap The FlatMap operator transforms an Observable by applying a

    function that you specify to each item emitted by the source Observable, where that function returns an Observable that itself emits items. FlatMap then merges the emissions of these resulting Observables, emitting these merged results as its own sequence. Note that FlatMap merges the emissions of these Observables, so that they may interleave. In several of the language-specific implementations there is also an operator that does not interleave the emissions from the transformed Observables, but instead emits these emissions in strict order, often called ConcatMap or something similar. http://reactivex.io/documentation/operators/flatmap.html