Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

iOSCon

164 views

Published on

iOSCon - Introduction to Functional Reactive Programming

Published in: Mobile
  • Be the first to comment

  • Be the first to like this

iOSCon

  1. 1. Introduction to Functional Reactive Programming EliaszSawicki.com ( @EliSawic )
  2. 2. Functional Reactive Programming EliaszSawicki.com ( @EliSawic )
  3. 3. Streams EliaszSawicki.com ( @EliSawic )
  4. 4. Stream EliaszSawicki.com ( @EliSawic )
  5. 5. Arrays let values = [1, 2, 3, 4] let doubledValues = values.map { $0 * 2 } let higherThanTwo = values.filter { $0 > 2 } let sum = values.reduce(0, +) EliaszSawicki.com ( @EliSawic )
  6. 6. Filter EliaszSawicki.com ( @EliSawic )
  7. 7. Combine Latest EliaszSawicki.com ( @EliSawic )
  8. 8. Chaining manipulations let names = nameField.reactive.text EliaszSawicki.com ( @EliSawic )
  9. 9. Chaining manipulations names.filter { $0.characters.count >= 3} EliaszSawicki.com ( @EliSawic )
  10. 10. Chaining manipulations names.filter { $0.characters.count >= 3} .map { return "Dear" + $0 } EliaszSawicki.com ( @EliSawic )
  11. 11. Chaining manipulations let prefixedNames = names.filter { $0.characters.count >= 3} .map { return "Dear" + $0 } let combined = combineLatest(prefixedNames, surnames) combined.observeValues { prefixedNames, surname in print("Form input is (prefixedNames) (surname)") } EliaszSawicki.com ( @EliSawic )
  12. 12. www.rxmarbles.com EliaszSawicki.com ( @EliSawic )
  13. 13. ReactiveSwift EliaszSawicki.com ( @EliSawic )
  14. 14. Events flow EliaszSawicki.com ( @EliSawic )
  15. 15. Non-Terminating • Next EliaszSawicki.com ( @EliSawic )
  16. 16. Terminating • Completed • Failed • Interrupted (Reactive Cocoa) EliaszSawicki.com ( @EliSawic )
  17. 17. This screen is a signal EliaszSawicki.com ( @EliSawic )
  18. 18. Represents events over time EliaszSawicki.com ( @EliSawic )
  19. 19. Observe EliaszSawicki.com ( @EliSawic )
  20. 20. EliaszSawicki.com ( @EliSawic )
  21. 21. If you don't observe, it's gone EliaszSawicki.com ( @EliSawic )
  22. 22. Observing presentation.observeValues { idea in remember(idea: idea) } presentation.observeCompleted { print("Time for a break") } EliaszSawicki.com ( @EliSawic )
  23. 23. Signal producer EliaszSawicki.com ( @EliSawic )
  24. 24. Represents a tasks EliaszSawicki.com ( @EliSawic )
  25. 25. Does not start it's work if not asked EliaszSawicki.com ( @EliSawic )
  26. 26. Producing presenter.startWithSignal { (signal, _) in signal.observeValues { idea in print(idea) } signal.observeCompleted { print("Time for a break") } } EliaszSawicki.com ( @EliSawic )
  27. 27. Hot vs Cold EliaszSawicki.com ( @EliSawic )
  28. 28. Signal SignalProducer presentation.observeValues presentation.startWithValues EliaszSawicki.com ( @EliSawic )
  29. 29. Signal SignalProducer presentation.observeValues presentation.startWithValues emits values all the time waits for your request EliaszSawicki.com ( @EliSawic )
  30. 30. Properties EliaszSawicki.com ( @EliSawic )
  31. 31. Bindings EliaszSawicki.com ( @EliSawic )
  32. 32. Binding example let (slides, _) = Signal<Slide, NoError>.pipe() label.reactive.text <~ slides.map { return "Slide: ($0.number)" } EliaszSawicki.com ( @EliSawic )
  33. 33. Memory Management EliaszSawicki.com ( @EliSawic )
  34. 34. Disposables EliaszSawicki.com ( @EliSawic )
  35. 35. Free your memory let disposable = signal.observeValues { value in ... } deinit { disposable.dispose() } EliaszSawicki.com ( @EliSawic )
  36. 36. FUNctional reactive programming EliaszSawicki.com ( @EliSawic )

×