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

ReactiveCocoa

nghialv
December 14, 2015

 ReactiveCocoa

nghialv

December 14, 2015
Tweet

More Decks by nghialv

Other Decks in Education

Transcript

  1. 5෼ͰReactiveCocoa TechLT๨೥ձ2015

  2. • Le Van Nghia (ΪΞ) • @nghialv (twitter: nghialv2607) ΞΧ΢ϯτ

    • CyberAgentʹ৽ଔೖࣾ • FRESH!ੜ์ૹ , AmebaΞϓϦ
  3. “2015೥΋ٕज़తʹมԽͷଟ͍1೥Ͱͨ͠Ͷ” Πϕϯτ֓ཁΑΓ

  4. ٕज़ؔ܎ͳ͍Ͱ͕͢ɼCyberAgentͷϩΰ΋มԽ͞Ε·ͨ͠ɻ

  5. http://abema.tv https://amebafresh.tv Coming Soon!

  6. • ϓϩδΣΫτϝϯόʔ໿30໊ • αʔόʔ & Πϯϑϥ x 6 • Go

    1.5.2, Docker 1.9.0, AWS, Microservices, RESTful API (goji) • ϑϩϯτ x 6 • Node.js v4, TypeScript 1.6, React/Flux, SPA + SSR • iOS x 4 • Swift 2.1, ReactiveCocoa, MVVM • Android x 4 • Kotlin, Rx • σβΠφʔ x 3 • Sketch • πʔϧ • Slack + Hubot(ChatOps), Github Enterprise, CircleCI (Enterprise), Fabric, JIRA Agile, Mackerel…
  7. speakerdeck.com/stormcat24/next-fresh-applications-with-amazon-ecs ࢁా͞Μ @stormcat24

  8. 2015೥ͷiOS։ൃ WWDC 2014 1.0 - closure, first-class functions - type

    safety and type inference - generics - tuples and multiple return values - seamless access to Objective C, C, C++ 2/2015 1.2 - incremental builds - faster executables - better compiler diagnostics - stability improvements 9/2015 2.0 - error handling model - guard, defer - protocol extension - protocol-oriented programming - ίϯύΠϧ࣌ؒ - ίϯύΠϥͷόά AmebaΞϓϦ FRESH!ੜ์ૹ - ReactiveCocoa - MVVMϞσϧ 1.0ಋೖ - ίϯύΠϧ࣌ؒ - ֎෦ϥΠϒϥϦͷෆ҆ఆ ίʔυ͕ଟ͘ͳͬͨ࣌఺ - 100% Swift 1.2 - MVCϞσϧ - Future - Result
  9. 2015೥ͷiOS։ൃ 12/2015 Open source - source code - swift package

    manager - core libraries - ports for Linux Fall 2016 3.0 FRESH!ੜ์ૹ - Swift2.0ʹҠಈ - ίϯύΠϧ͸΍͘ͳͬͨ
  10. ReactiveCocoaͷλΠϜ

  11. ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive

    Programming. It provides APIs for composing and transforming streams of values over time.
  12. ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive

    Programming. It provides APIs for composing and transforming streams of values over time.
  13. ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive

    Programming. It provides APIs for composing and transforming streams of values over time.
  14. None
  15. water pipe event pipe

  16. event signal observe sink

  17. event signal observe sink let (signal, sink) = Signal<String, ErrorType>.pipe()

    signal
 .observe { event in // hi } sink.sendNext("hi")
  18. event signal observe sink observe let (signal, sink) = Signal<String,

    ErrorType>.pipe() signal
 .observe { event in // hi } sink.sendNext("hi") signal
 .observe { event in // hi }
  19. event signal observe sink observe observe͢ΔલͷeventΛड͚औΕͳ͍

  20. ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive

    Programming. It provides APIs for composing and transforming streams of values over time.
  21. event signal observe sink transform

  22. event signal observe sink let (signal, sink) = Signal<String, ErrorType>.pipe()

    signal
 .map { string in string.uppercaseString } .observe { event in // “HI" } sink.sendNext("hi") transform hi HI
  23. event observe sink

  24. throttle event signal observe sink throttle let (signal, sink) =

    Signal<Int, ErrorType>.pipe() signal .throttle(0.5, onScheduler: QueueScheduler()) .observe { num in // 1 // 4 } sink.sendNext(1) sink.sendNext(2) sink.sendNext(3) // after 0.5 second sink.sendNext(4)
  25. combinePrevious let (signal, sink) = Signal<Int, ErrorType>.pipe() signal .combinePrevious(0) .observe

    { pre, cur in // pre = 0, cur = 1 // pre = 1, cur = 2 } sink.sendNext(1) sink.sendNext(2)
  26. Transforming • map • filter • reduce • collect •

    mapError • observeOn • ignoreNil • timeoutWithError • take • delay • skip • takeUntil • combinePrevious • takeLast • throttle • promoteErrors
  27. ReactiveCocoa (RAC) is a Cocoa framework inspired by Functional Reactive

    Programming. It provides APIs for composing and transforming streams of values over time.
  28. • compose <A, B, C> (A -> B, B ->

    C) -> A -> C f1: A -> B f2: B -> C f3: C -> D f = f1ɾf2ɾf3 => f: A -> D
  29. Signal, TransformΛ૊Έ߹Θͤͯɼ
 ผͷSignalΛߏ੒Ͱ͖Δ

  30. event signal observe sink transform transform ࿈ଓͰTransformΛ૊Έ߹ΘͤΔ

  31. observe ෳ਺SignalΛ૊Έ߹ΘͤΔ

  32. ͜Ε΋Ͱ͖ΔΑʂ

  33. zip let (numbersSignal, numbersSink) = Signal<Int, NoError>.pipe() let (lettersSignal, lettersSink)

    = Signal<String, NoError>.pipe() let newSignal = zip(numbersSignal, lettersSignal) newSignal .observe { event in
 println(event)
 } numbersSink.sendNext(1) // nothing printed lettersSink.sendNext("A") // prints (1, A) numbersSink.sendNext(2) // nothing printed lettersSink.sendNext("B") // prints (1, B) lettersSink.sendNext("C") // nothing printed lettersSink.sendNext("D") // nothing printed
  34. Ͳͷͱ͜Ζʹ࢖͑Δ?

  35. • શ෦ • Model • ViewModel • View • Manager

    • Api • …
  36. ͝ࢹௌ͋Γ͕ͱ͏͍͟͝·ͨ͠ʂ