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

ReactiveSwift

73b5e9bf5f8ba0669b30c80f710f9904?s=47 Teddy Ku
January 27, 2017

 ReactiveSwift

Intro to ReactiveSwift

73b5e9bf5f8ba0669b30c80f710f9904?s=128

Teddy Ku

January 27, 2017
Tweet

Transcript

  1. Teddy Ku January 27, 2017 ReactiveSwift

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

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

    Swift rewrite • Type safety • Performance: didSet instead of What isReactiveSwift?
  4. • UITextFieldDelegate? • UITextFieldTextDidChange notification? • textField.addTarget(self, action: #selector(textFieldDidChange),

  5. Too much state

  6. Signals = Events over time

  7. Less state, less bugs

  8. Signals

  9. EMAIL PASSWORD PASSWORD BUTTON ENABLED bind Signals

  10. T EMAIL PASSWORD PASSWORD BUTTON ENABLED foo@bar.com bind Signals

  11. T T EMAIL PASSWORD PASSWORD BUTTON ENABLED foo@bar.com bind ***************

    Signals
  12. T T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED foo@bar.com

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

    TTF foo@bar.com bind *************** *************** Signals
  14. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T foo@bar.com bind *************** *************** Signals
  15. T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON ENABLED

    F TTF T T TTT foo@bar.com bind *************** *************** Signals
  16. 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
  17. 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
  18. Behavior is defined linearly and concisely

  19. Live demo

  20. 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
  21. Live demo

  22. RxMarbles T TTF T T TTT EMAIL PASSWORD PASSWORD BUTTON

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

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

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