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

ReactiveSwift

Teddy Ku
January 27, 2017

 ReactiveSwift

Intro to ReactiveSwift

Teddy Ku

January 27, 2017
Tweet

More Decks by Teddy Ku

Other Decks in Programming

Transcript

  1. What is • 2012: built for Github desktop app •

    Streams of values over time • Why? • ReactiveX: RxJava, Rx.NET • Reduce state, reduce bugs ReactiveCocoa
  2. • 2016: ReactiveCocoa split -> ReactiveSwift and ReactiveCocoa • Pure

    Swift rewrite • Type safety • Performance: didSet instead of What isReactiveSwift?
  3. T T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED [email protected]

    bind *************** *************** Signals
  4. T T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED F

    TTF [email protected] bind *************** *************** Signals
  5. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T [email protected] bind *************** *************** Signals
  6. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T T TTT [email protected] bind *************** *************** Signals
  7. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T T TTT Translate to ReactiveSwift 1. Take latest string values 2. Check if each is not empty 3. Combine latest booleans 4. Return true if all not empty
  8. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T T TTT |> is equivalent to Translate to ReactiveSwift 1. Take latest string values 2. Check if each is not empty 3. Combine latest booleans 4. Return true if all not empty
  9. 1. Take latest string values 2. Validate email and password

    3. Validate passwords match 4. Combine all validation results 5. BUT: don’t show errors if all fields aren’t filled out yet Error Validation
  10. RxMarbles T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON

    ENABLED F TTF T T TTT HTTP://RXMARBLES.COM/#COMBINELATEST
  11. Recap • Less state, less bugs • Define behavior linearly

    & concisely • Types: Signal, Event https://github.com/tkuichooseyou/ReactiveSwiftTalk
  12. Bonus • Signals representing other async events • Network Requests

    • Loading from disk • Sockets - real time updates • Throttle • Retry • Cancel network requests