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

Reactive Thinking in iOS Development - Reactive Amsterdam Meetup

Reactive Thinking in iOS Development - Reactive Amsterdam Meetup

In a world where Imperative Programming is the most used paradigm, Reactive comes up to make our code more reusable, robust, and stateless. Learn what Functional Reactive Programming means and how it could help you with problems you have to face daily in your projects. We’ll present basic concepts and practical examples for iOS developers that will help you to start thinking in streams, observers, .. and mix them with cool Swift functional concepts.

B0a336761194918a853deeff1f22b537?s=128

Pedro Piñera Buendía

May 12, 2016
Tweet

More Decks by Pedro Piñera Buendía

Other Decks in Technology

Transcript

  1. REACTIVE THINKING IN IOS DEVELOPMENT ! @PEPIBUMUR / @SAKY

  2. WHO? @pepibumur iOS Developer at SoundCloud GitHub: pepibumur Twitter: pepibumur

    @saky iOS Developer at Letgo GitHub: isaacroldan Twitter: saky GitDo.io our spare time project
  3. CODEMOTION AMSTERDAM REACTIVE AMSTERDAM THANKS FABIO FOR INVITING

  4. WE DID IT AGAIN

  5. WE DID IT AGAIN WE REINVENTED OUR OWN TALK

  6. WE DID IT AGAIN WE REINVENTED OUR OWN TALK IT'S

    MAGIC
  7. LE NEW IOS REACTIVE THINKING TALK WITH ❤, MORE INTERACTIVE

    AND IOS FOCUSED
  8. None
  9. INDEX 1. Why Reactive? I'm happy being imperative 2. What

    do we need? 3. How can I be Reactive? 4. It looks magic. Any Downside?
  10. WHY REACTIVE? I'M HAPPY BEING IMPERATIVE

  11. REACTIVE ADVANTANGES (ON A DIFFERENT PLATFORM) COMPOSABILITY, EASE THREADING, STATELESS

    AND REUSABLE CODE, SINGLE SOURCES OF TRUTH.
  12. WHAT DO WE NEED?

  13. 1. YOU NEED A FRAMEWORK FOUNDATION COMPONENTS, OPERATORS, ...

  14. 2. YOU HAVE TO CHANGE YOUR MINDSET

  15. BEFORE SWIFT A PREDOMINANT FRAMEWORK, REACTIVECOCOA

  16. REACTIVECOCOA Version 1.0 (Objective-C) - February 2014 Version 2.0 (Objective-C)

    - September 2014 Version 3.0 (Objective-C) - September 2015 Swift launch - June 2014 Version 4.0 (Swift) - January 2015
  17. BUT... ALTERNATIVES CAME OUT

  18. RXSWIFT FROM REACTIVEX, SAME COMPONENTS, NAMING,...

  19. RXSWIFT > More aligned to Rx > Not external dependencies.

    > More aligned with Swift error handling. > It provides extensions for Cocoa/UIKit, RxCocoa
  20. THERE ARE SOME OTHERS > BrightFutures > ReactKit > Bond

    > More and more... PromiseKit, Bolts...
  21. None
  22. HOW CAN I BE REACTIVE? BETTER WITH LIVE EXAMPLES TIME

    TO CODE! !"
  23. DEMO 1 UI BINDINGS

  24. DEMO 2 I WANT MY UBER ! HISTORY

  25. ! DOWNSIDES BECAUSE YES... IT COULDN'T BE PERFECT

  26. DEBUGGING DEBUG OPERATOR IN RXSWIFT

  27. let tracksFetcher = api.fetchTracks // Background .asObservable() .retry(3) .catchErrorJustReturn([]) .map(TrackEntity.mapper().map)

    .filter { $0.name.contains(query) } .flatMap { self.rx_trackImage(track: $0) } .observeOn(MainScheduler.instance) // Main thread
  28. let tracksFetcher = api.fetchTracks // Background .asObservable .debug("after_fetch") // <--

    Debugging probes .retry(3) .catchErrorJustReturn([]) .map(TrackEntity.mapper().map) .debug("mapped_results") // <-- Debugging probes .filter { $0.name.contains(query) } .flatMap { self.rx_trackImage(track: $0) } .observeOn(MainScheduler.instance) // Main thread
  29. //let tracksFetcher = api.fetchTracks // Background // .asObservable .debug("after_fetch") //

    <-- Debugging probes // .retry(3) // .catchErrorJustReturn([]) // .map(TrackEntity.mapper().map) .debug("mapped_results") // <-- Debugging probes // .filter { $0.name.contains(query) } // .flatMap { self.rx_trackImage(track: $0) } // .observeOn(MainScheduler.instance) // Main thread
  30. > [after_fetch] Next Event... // Downloaded tracks > [mapped_results] Error

    ... // Detected error after mapping > [...]
  31. UNSUBSCRIPTION YOU NEED TO TAKE CARE OF THE LIFECYCLE OF

    YOUR OBSERVABLES
  32. RETAIN CYCLES

  33. CONCLUSIONS

  34. PREVENTS STATEFUL CODE

  35. DATA FLOW MANIPULATION BECOMES EASIER

  36. BUT... !

  37. YOU COUPLE YOUR PROJECT TO A LIBRARY !

  38. REACTIVE CODE SPREADS LIKE A VIRUS ! OVERREACTIVE ⚠

  39. DEFINE REACTIVE DESIGN GUIDELINES AND STICK TO THEM

  40. HAVE REACTIVE FUN !

  41. REFERENCES > rxmarbles.com > RxSwift Community > RxSwift Repository >

    ReactiveCocoa
  42. WE ARE HIRING PEPI@SOUNDCLOUD.COM - ISAAC@LETGO.COM ❄ BERLIN - BARCELONA

    !
  43. None
  44. THANKS QUESTIONS? SLIDES HTTP://BIT.LY/1RFWLCI @SAKY - @PEPIBUMUR IMAGES BELONG TO

    UNSPLASH.COM