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

Combine! All the things

Combine! All the things

Ritesh Gupta

July 28, 2019
Tweet

More Decks by Ritesh Gupta

Other Decks in Programming

Transcript

  1. Combine • It provides a declarative Swift API for processing

    values over time • These values can represent many kinds of asynchronous events • Customise handling of asynchronous events by combining event-processing operators
  2. Rx Programming • Observer Pattern (publish >> observe) • Operations

    (dependent tasks) • Simple (yet powerful) Operators like merge, zip, debounce… • Open Source: ReactiveSwift, RxSwift
  3. Why Rx? • multiple async tasks • better state management

    • loose coupling of components • declarative & cleaner api
  4. Publisher • emit sequence of values over time • delivers

    values to one or more Subscriber instances • protocol with two generic types (Output, Error) • completion via .finished or .failure
  5. • Notification Publisher • URLSession Publisher • Just, Future •

    CurrentValueSubject, PassthroughSubject Free Publishers
  6. Subscriber • receive emitted values from a Publisher • represents

    end of the chain of a stream • protocol with two generic types (Input, Error) • can cancel a subscription • Sink, Assign, AnySubscriber
  7. • `receive(on:)` affects downstream events • `subscribe(on:)` affects upstream events

    • In the example, requests to `$queryPublisher` are performed on `backgroundQueue`, but elements received from it are performed on `Dispatch.main` Threading
  8. • pre-defined functions (publishers) • used b/w a publisher &

    a subscriber • transform the stream • map, flatMap, filter, merge, zip, debounce… Operators
  9. Map

  10. Zip