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

ReactiveCocoa for a Better World

ReactiveCocoa for a Better World

Cocoa apps spend a lot of time waiting and then reacting. We wait for the user to do something in the UI. Wait for a network call to respond. Wait for an asynchronous operation to complete. Wait for some dependent value to change. And then they react. But all those things—all that waiting and reacting—is usually handled in many disparate ways. That makes it hard for us to reason about them collectively, chain them, or compose them in any uniform, high-level way. We can do better. ReactiveCocoa is a framework for composing and transforming sequences of values. We'll talk about how we can use ReacticeCocoa to write better, more succinct and more expressive code.

62e8c8bfaa8d755cab82accb48d335c8?s=128

Josh Abernathy

August 11, 2012
Tweet

Transcript

  1. (Bonjour.)

  2. Josh Abernathy @joshaber

  3. None
  4. None
  5. Story time.

  6. None
  7. None
  8. None
  9. Reactive Extensions (Rx)

  10. Erik Meijer

  11. ReactiveCocoa (RAC)

  12. for a ReactiveCocoa Better World

  13. PHILOSOPHY

  14. Idea > Code

  15. Not “easy”

  16. But it’s good.

  17. “A framework for composing and transforming sequences of values.”

  18. “A framework for composing and transforming sequences of values.” —

    Scumbag Josh
  19. It’s like a series of tubes...

  20. “A sequence of values over time.”

  21. “A sequence of values over time.” — Me, just now

  22. RACSubscribable

  23. RACSubscribable

  24. RACSubscribable

  25. RACSubscriber

  26. Subscription Iteration

  27. That’s it!

  28. ???

  29. Async work

  30. Network request

  31. UI events

  32. KVO

  33. ???

  34. KVO property = UI events = Network request = Async

    work = ??? = Subscribables
  35. Shared Vocabulary

  36. Shared Toolset

  37. Composable

  38. It’s all about The Operators

  39. Compose Combine Transform

  40. None
  41. None
  42. PHILOSOPHY

  43. None
  44. Expressive

  45. Expressive (But dense.)

  46. None
  47. Code Locality

  48. None
  49. Less State

  50. None
  51. It’s all about The Operators

  52. It’s all about The Operators (There are a lot of

    operators.)
  53. -select: Hi to all HI ALL TO

  54. -where: A B A A A

  55. +merge:

  56. -throttle:

  57. -selectMany:

  58. -selectMany:

  59. -selectMany: “When I get a value, subscribe to the next

    subscribable.”
  60. -selectMany: “When I get a value, subscribe to the next

    subscribable.”
  61. -selectMany: Look, it’s about chaining ok?

  62. None
  63. -takeUntil:

  64. -catch:

  65. Errors? What errors?

  66. -catch:

  67. Where do subscribables Come from?

  68. Hot vs. Cold

  69. Honey badger don’t care Hot: Everyone gets the same thing

  70. Honey badger most certainly does care Cold: Everyone’s separate

  71. PHILOSOPHY

  72. So Lazy.

  73. Subscribing can have side effects

  74. -retry:

  75. -repeat:

  76. Where do subscribables Come from? No seriously,

  77. Cold: +createSubscribable:

  78. None
  79. None
  80. Hot: Subjects

  81. None
  82. None
  83. RACSubject

  84. RACAsyncSubject RACSubject

  85. RACAsyncSubject RACSubject RACReplaySubject

  86. RACAsyncSubject RACSubject RACReplaySubject RACBehaviorSubject

  87. None
  88. -defer: “I’ll give you a subscribable when someone subscribes.” Hot

    to Cold
  89. -publish/-multicast: “Funnel everything through one subscription.” Hot to Cold

  90. PHILOSOPHY

  91. Not “easy”

  92. But it’s good.

  93. github.com/github/ReactiveCocoa More Info: Reactive Extensions (Rx) @joshaber

  94. (Fin.)