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

Combine - Diving into Apple’s Reactive Programming

Swift India
January 25, 2020

Combine - Diving into Apple’s Reactive Programming

Swift Hyderabad Chapter 5
Speaker: Ankush Bhatia

Abstract: At WWDC 2019, Apple introduced their own version of reactive framework which can be a new approach for working with asynchronous code. We will be exploring fundamentals of Combine with its application.

Bio: Sr. iOS Engineer @ Mutual Mobile. He has been working on Swift language from the day it came into this 🌎.
Linkedin: https://www.linkedin.com/in/ankush-bhatia-ios

Swift India

January 25, 2020
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. ANKUSH BHATIA Sr. iOS Engineer @Mutual Mobile Twitter: @ankush1419 Github:

    ankush-bhatia Medium: @ankush_bhatia Linkedin: ankush-bhatia-ios Web: ankushbhatia.com
  2. COMBINE PROBLEMS WITH IMPERATIVE ASYNC PROGRAMMING ▸ Order of execution

    ▸ State management ▸ Different APIs to execute asynchronous code Task 1 Task 2 Task 3 Task 4 Tasks Time
  3. COMBINE WHAT IS COMBINE? ▸ Declarative API for processing values

    over time. ▸ Built for handling asynchronous events easily. ▸ Alternate approach. ▸ Type Safe ▸ Only Available from iOS 13.0 and mac OS Catalina or later.
  4. COMBINE PUBLISHERS ▸ Publishers emits values over time to the

    interested parties. ▸ It can do two type of things: ▸ Send generic output of Output type. It can be anything from value to object. ▸ Can send completion of success or failure. ▸ Publisher do not emit any values if no one is there to listen. (no subscribers currently subscribed to publisher.)
  5. COMBINE SUBSCRIBERS ▸ Subscribers are the ones which act upon

    the data received from the publishers. ▸ Combine provides us two built in subscribers. ▸ Sink: Allows to get callback of the data in the completion block. ▸ Assign: Allows to assign output to some property on data model or UI view to update.
  6. COMBINE OPERATORS ▸ These are something which can be called

    as middleware which act upon existing publishers and provides a new publisher. ▸ Order of the operators matter as the Output of one should match with the input of the another. ▸ Upstream: Input of the operator. ▸ Downstream: Output of the operator. ▸ Uses: ▸ Functional Transformations (Map, Reduce, Filter) ▸ Thread handling. ▸ Error handling.
  7. COMBINE LIFE CYCLE 1. Subscriber subscribes to publisher. 2. Publisher

    sends subscriptions to subscriber. 3. Subscriber uses subscription to request values from publisher. 4. Publisher sends values as requested by subscriber. 5. Publisher sends completion or failure to end subscription. WWDC Slides