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

Dive to Reactive Extension with Swift

dameleon
November 21, 2016

Dive to Reactive Extension with Swift

Concept and implementation of Reactive Extension for beginners.
SAMPLE CODES: https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03

dameleon

November 21, 2016
Tweet

Other Decks in Programming

Transcript

  1. ΞδΣϯμ ▸ Reactive Extensionͱ͸ ▸ αϯϓϧΞϓϦ ▸ Deep dive to

    Rx ▸ ϥΠϒϥϦ ※αϯϓϧίʔυ౳Ͱ࢖༻͢Δݴޠ, ࣮૷ܥ͸Swift3.0.1 + RxSwift(3.0.0-rc.1)Λ࢖༻͢Δ ※αϯϓϧίʔυ͕େྔʹͳͬͨͷͰɺαϯϓϧίʔυͱ߹ΘͤͯӾཡΛਪ঑͢Δ
  2. Reactive Extensionͱ͸ Rx = Observables + LINQ + Schedulers ▸

    Observables: Observer PatternͰ࣮૷͞Εͨ࣌ܥྻͰൃੜ͢Δσʔλू ߹ ▸ LINQ: ओʹ.NET FrameworkͰར༻Մೳͳσʔλू߹ʹରͯ͠ΫΤϦϯ άΛߦ͏࢓૊Έ(RxͰ͸Operatorͱݺ͹ΕΔ) ▸ Schedulers: ͍ͭ, Ͳ͜Ͱ஋Λൃੜ, ॲཧ, ߪಡ͢Δ͔Λѻ͏εέδϡʔϥ ೚ҙͷεέδϡʔϥͰɺ࣌ܥྻͰൃੜ͢Δσʔλू߹(Stream)ʹ ରͯ͠ΫΤϦΛൃߦ͠ɺ݁ՌΛߪಡ͢Δ ͜ͱ͕Ͱ͖Δ࢓૊Έ
  3. Reactive Extensionͱ͸ ͜͜·Ͱͷ·ͱΊ ▸ Rx = Observables + LINQ +

    Schedulers ▸ ࣌ܥྻͰൃੜ͢Δσʔλू߹ΛετϦʔϜͱݺͿ ▸ Rxͷಈ࡞͸Marble DiagramsͰද͞ΕΔ
  4. αϯϓϧΞϓϦ Github Repository Search APIͰݕࡧΛߦ͍ɺ݁ՌΛදࣔ͢Δ ▸ ೖྗจࣈΛݕࡧϫʔυͱͯ͠ɺGithubͷRepository Search APIΛ call͢Δ

    ▸ Ϩεϙϯεσʔλ͔ΒɺϦϙδτϦ໊ͷҰཡΛऔಘ͠ɺ TableViewʹදࣔ͢Δ ▸ ΤϥʔͳͲͷҟৗܥ͸Ұ୴ߟྀ͠ͳ͍
  5. αϯϓϧΞϓϦ Rx͋ΓͰߟ͑ͯΈΔ - ֓೦ฤ ▸ UISearchBarͷೖྗΛObservableͰड͚Δ ▸ .throttle() OperatorͰೖྗΛؒҾ͘ ▸

    .distinctUntilChanged() OperatorͰॏෳೖྗΛ๷ࢭ ▸ ೖྗΛURLSession.rx.json(url)ͰϦΫΤετ͠ɺ݁ՌͷObservableΛड͚औΔ ▸ ݁ՌͷετϦʔϜΛtableViewʹbind͠ɺObservableͷ݁ՌʹΑͬͯ tableView͕ߋ৽͞ΕΔΑ͏ʹ͢Δ ObservableͱOperator(֤छૢ࡞Λߦ͏ϝιου)Λ༻͍Δͱ ͜ͷΑ͏ʹߟ͑ɺ࣮૷Ͱ͖Δ
  6. Deep dive to Rx Observableͷੜ੒ͱߪಡ(Observable.create) - ·ͱΊ ▸ Observable<Element> ▸

    Elementܕͷ஋ʹରͯ͠ɺΫΤϦ, ߪಡΛߦ͏ͨΊͷΫϥε (جఈprotocol͸ObservableConvertibleType) ▸ Streamͷ࣮ମ ▸ ༷ʑͳOperatorΛඋ͑Δ ▸ ΫΤϦ: map, flatMap, take, filter… ▸ ߪಡ: subscribe, bindTo…
  7. Deep dive to Rx Observableͷੜ੒ͱߪಡ(Observable.create) - ·ͱΊ ▸ AnyObserver<Element> ▸

    ֤छ஋, ΠϕϯτΛൃߦ͢ΔͨΊͷΫϥε(جఈprotocol͸ ObserverType) ▸ onNext(element: Element), onError(error: Error), onCompleted()ͷϝιουΛඋ͑Δ
  8. Deep dive to Rx Observableͷੜ੒ͱߪಡ(Observable.create) - ·ͱΊ ▸ Disposable ▸

    ߪಡͷഁغΛߦ͏ͨΊͷϝιουΛఆٛͨ͠protocol ▸ subscribe()ͷ໭Γ஋͸DisposableͰɺdispose()Λcall͢ Δ͜ͱʹΑΓߪಡͷഁغΛߦ͏͜ͱ͕Ͱ͖Δ
  9. Deep dive to Rx Observableͷੜ੒ͱߪಡ(Observable.create) - ·ͱΊ ▸ ObservableͷϥΠϑαΠΫϧ ▸

    onError(error: Error)ͱonCompleted()͕௨஌͞Εͨ Observable<Element>͸׬ྃঢ়ଶʹͳΓɺͦͷޙ͸஋, Π ϕϯτΛྲྀ͢͜ͱ͸Ͱ͖ͳ͍
  10. Deep dive to Rx Observableͷੜ੒ͱߪಡ(PublishSubject) - ·ͱΊ ▸ PublishSubject<Element> ▸

    ObservableType, ObserverTypeͷͲͪΒͷੑ࣭΋උ͑ͨΫϥ ε(= ஋, Πϕϯτͷൃੜ, ߪಡΛͲͪΒ΋ߦ͑Δ)Λ”Subject” ͱݺͿ ▸ PublishSubject<Element>͸લड़ͷMarble Diagramsͷ௨ Γɺon(Next|Error|Completed)Λߦ͏ͱɺͦͷ࣌఺Ͱͷશͯ ͷSubscriberʹͦͷ௨஌Λߦ͏Subject ▸ “Subject”ʹ͸ଞʹ΋ReplaySubject, VariableͳͲ͕͋Δ
  11. Deep dive to Rx Observableͷੜ੒ͱߪಡ(PublishSubject) - ·ͱΊ ▸ DisposeBag ▸

    DisposeBagͷΠϯελϯε͕dealloc͞ΕΔࡍʹɺొ࿥͞ ΕͨDisposableͳΠϯελϯεΛશͯdispose()͢ΔΫϥ ε ▸ ৄࡉ͸ޙड़
  12. Deep dive to Rx Hot, Cold Observable - ͱ͸ Observableʹ͸ɺHot,

    Cold ͱ͍͏ 2ͭͷੑ࣭͕͋Γɺ֤Operator͸ඞͣͲͪΒ͔ͷੑ࣭Λඋ͑ͨ ObservableΛੜ੒͢Δ
  13. Deep dive to Rx Hot, Cold Observable - ͱ͸ Cold

    Observable Hot Observable ஋ͷൃߦ subscribe()࣌ ਵ࣌ Streamͷ෼ذ ͠ͳ͍ ͢Δ ্ྲྀʹର͢ΔӨڹ ͳ͠ ্ྲྀͷCold Observableͷ஋ Λཁٻ͢Δ
  14. Deep dive to Rx Hot, Cold Observable - ஋ͷൃߦ, Streamͷ෼ذ

    Observable.createͷྫʹɺ஋ͷൃߦ࣌ؒΛ෇Ճ͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#observablecreateͷྫʹ஋ͷ ൃߦ࣌ؒΛ෇Ճ͢Δ ▸ subscribe()Λߦ͏(Observer͕౉͞ΕΔ)͝ͱʹɺ஋͕ൃߦ ͞ΕΔ ▸ subscribe()ΛߦͬͨࡍʹɺStream͕Ͱ͖Δ ▸ ͭ·Γɺ1ͭͷStream͸෼ذ͠ͳ͍
  15. Deep dive to Rx Hot, Cold Observable - ஋ͷൃߦ, Streamͷ෼ذ

    PublishSubjectͷྫʹɺ஋ͷൃߦ࣌ؒΛ෇Ճ͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#publishsubjectͷྫʹ஋ͷൃ ߦ࣌ؒΛ෇Ճ͢Δ ▸ subscribe()Λߦ͏(Observer͕౉͞ΕΔ)͔Ͳ͏͔ʹݶΒͣɺ ஋͕ൃߦ͞ΕΔ ▸ subscribe()ΛߦΘͳ͘ͱ΋ɺStream͕Ͱ͖Δ ▸ ͭ·Γɺ1ͭͷStream͕෼ذ͢Δ
  16. Deep dive to Rx Hot, Cold Observable - ্ྲྀʹର͢ΔӨڹ Cold

    ObservableΛHot Observableʹม׵͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#cold-observableΛhot- observableʹม׵͢Δ ▸ Cold Observableʹରͯ͠publish()Λcall͢ΔͱɺHot Observableͷੑ࣭Λඋ͑ͨ ConnectableObservable<Element>ͷΠϯελϯε͕ฦΔ ▸ ConnectableObservable<Element>ͷΠϯελϯεͷconnect()Λcall͢Δͱ ▸ ্ྲྀͷCold Observableʹ஋Λཁٻ͠ɺ஋͕ൃߦ͞ΕΔ ▸ ൃߦ͞Εͨ஋͸ɺͦͷ࣌఺ͰͷSubscriberʹ௨஌͞ΕΔ ▸ લड़ͷαϯϓϧͰ͸ɺ”C"ͷSubscriberʹ͸஋͕ྲྀΕͳ͍ ▸ Cold to HotΛߦ͏Operator͸͍͔ͭ͋͘Δ(shareReplay(n)౳)
  17. Deep dive to Rx Hot, Cold Observable - ্ྲྀʹର͢ΔӨڹ Hot

    ObservableΛCold Observableʹม׵͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#hot-observableΛcold- observableʹม׵͢Δ ▸ Hot Observableʹରͯ͠ɺಛఆͷOperator(ྫͷ৔߹͸map())Λcall͢ΔͱɺCold Observableͳ Observable<Element>͕ฦΔ ▸ Cold to Hotม׵, Subject౳Ҏ֎ͷOperator͸ɺ΄΅શͯCold ObservableʹͳΔ ▸ Cold ObservableΛsubscribe()͢ΔͱɺͦͷCold Observable͕ج఺ͱͳΓStream͸෼ذ͠ͳ͘ͳΔ(= Subscriber͝ͱʹStream͕Ͱ͖Δ) ▸ ྫͰ͸ɺ"A", "B", “C"ͷonNextͰɺmap()Ͱ෇Ճ͞Εͨ࣌ࠁ͕શͯҟͳ͍ͬͯΔ఺ʹ஫໨ ▸ ͭ·ΓSubscriberͷ਺͚ͩɺ`map()`͸ॲཧ͞ΕΔ͜ͱʹͳΔ ▸ ͦͷCold ObservableΛsubscribe()ͨ͠ͱ͖ɺطʹ্ྲྀͷHot Observableͷ஋͕ൃߦ͞Ε͍ͯͨ৔߹ɺͦͷ ஋Λ؍ଌ͢Δ͜ͱ͸Ͱ͖ͳ͍(αϯϓϧ಺, "C"ͷSubscriber͸ɺ"hoge", "fuga"Λ؍ଌͰ͖ͳ͍)
  18. Deep dive to Rx Hot, Cold Observable - ·ͱΊ Cold

    Observable Hot Observable ஋ͷൃߦ subscribe()࣌ ਵ࣌ Streamͷ෼ذ ͠ͳ͍ ͢Δ ্ྲྀʹର͢ΔӨڹ ͳ͠ ্ྲྀͷCold Observableͷ஋ Λཁٻ͢Δ Observable<Element>Λsubscribe()͢Δ৔߹ʹ͸ɺͦͷੑ࣭ΛΑ͘ݟ ۃΊΔඞཁ͕͋Δ
  19. Deep dive to Rx Hot, Cold Observable - ิ଍ .shareReplay(bufferSize:

    Int) Observable<Element>Λѻ͏৔߹ʹɺRxSwiftͷίʔυͷதͰසग़͢Δ Operator http://reactivex.io/documentation/operators/images/replay.c.png 2ͭͷSubscriberͦΕͧΕʹɺಉ͡஋ ͕ྲྀΕ͍ͯΔ఺ʹ஫໨
  20. Deep dive to Rx Hot, Cold Observable - ิ଍ -

    shareReplay ྫ͑͹ɺViewModelͷΑ͏ͳclass͔ΒViewControllerͳͲͷ֎෦ʹରͯ͠ Observable<Element>Λఏڙ͢Δ৔߹ʹɺViewModelࣗ਎ʹ͸ͷ Observable<Element>ͷSubscriber਺΍subscribe()ͷλΠϛϯάΛ੍ޚ͢Δ͜ͱ͸ ೉͍͠ ͦ͏͍ͬͨ৔߹ʹɺCold, Hot Observable͍ͣΕͷ৔߹΋ `observable.shareReplay(1)`ͱ͔ͯ͠Βఏڙ͢Δ͜ͱͰ ▸ Cold Observable: ௚લͷHot Observable, ΋͘͠͸ൃੜݩ·Ͱͷ Operatorͷॲཧ͕Subscriber͝ͱʹൃੜ͢ΔͷΛ๷ࢭ͢Δ ▸ Hot Observable: Subscriber͸௚ۙͷ஋Λඞͣߪಡ͢Δ͜ͱ͕Ͱ͖Δ
  21. Deep dive to Rx Hot, Cold Observable - ิ଍ -

    shareReplay https://github.com/ReactiveX/RxSwift/blob/4952adb27c684b47792923b00015516849061eab/ RxExample/RxExample/Examples/GitHubSignup/UsingVanillaObservables/ GithubSignupViewModel1.swift GithubSignupViewModel1 class͕֎෦ʹఏڙ͢ΔObservableͷ΄ͱΜͲ͕.shareReplay(1)͞Ε͍ͯΔ
  22. Deep dive to Rx Disposable - ͱ͸ subscribe(), bindTo()ͳͲͷϝιουͷ໭Γ஋ .dispose()ͱ͍͏ϝιουΛ༻͍ͯɺ

    ▸ ߪಡഁغͷཁٻ ▸ ߪಡͷ࣮૷͕ॴଐ͢ΔίϯςΩετͷϥΠϑαΠΫϧ ౳ͷλΠϛϯάͰɺߪಡΛഁغ͢Δ ߪಡͷഁغΛଵͬͨ৔߹ɺBAD ACCESS΍ϝϞϦϦʔΫ͕ൃੜ͢ ΔՄೳੑ͕͋Δ
  23. Deep dive to Rx Disposable - DisposeBag > Dispose bags

    are used to return ARC like behavior to RX ARCͷڍಈʹԊͬͯɺDisposable܈Λѻ͏Ϋϥε https://github.com/ReactiveX/RxSwift/blob/master/Documentation/GettingStarted.md#dispose-bags `DisposeBag`ͷΠϯελϯεʹ͸`Disposable`Λొ࿥͢Δ͜ͱ͕Ͱ͖ɺͦͷΠϯελϯε͕`deinit`͞Ε ͨ࣌ʹɺ๊͑ͨ`Disposable`܈Λશͯ`dispose()`͢Δ
  24. Deep dive to Rx Scheduler - Serial vs Concurrent Scheduler

    ▸ Serial Schedulers: ॱ࣍ॲཧ ▸ Concurrent Schedulers: ฒྻॲཧ
  25. Deep dive to Rx Scheduler - Serial Scheduler https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#serial-scheduler ▸

    SerialDispatchQueueSchedulerΛ༻͍ͯɺ DispatchQueue.global()Ͱॱ࣮࣍ߦ͞ΕΔSerial SchedulerΛੜ੒ ▸ subscribe()ͷ࣮ߦ͕ɺએݴॱʹߦΘΕ͍ͯΔ
  26. Deep dive to Rx Scheduler - Serial Scheduler https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#concurrent-scheduler ▸

    ConcurrentDispatchQueueSchedulerΛ༻͍ͯɺ DispatchQueue.global()Ͱฒྻ࣮ߦ͞ΕΔSerial SchedulerΛੜ੒ ▸ subscribe()ͷ࣮ߦ͕ɺผʑͷεϨουͰฒྻʹߦΘΕ͍ͯΔ
  27. Deep dive to Rx Scheduler - Builtin ▸ Serial Scheduler

    ▸ CurrentThreadScheduler ▸ MainScheduler ▸ SerialDispatchQueueScheduler ▸ ConcurrentScheduler ▸ ConcurrentDispatchQueueScheduler ▸ OperationQueueScheduler ͍͔ͭ͘ͷScheduler͕༻ҙ͞Ε͍ͯΔ ࣗ෼ࣗ਎ͰSchedulerΛ࣮૷͢Δ͜ͱ΋Մೳ https://github.com/ReactiveX/RxSwift/blob/master/Documentation/Schedulers.md#builtin-schedulers
  28. Deep dive to Rx Scheduler - SchedulerΛ੾Γସ͑Δ ▸ observeOn, subscribeOnͱ͍͏OperatorͰSchedulerΛ੾

    Γସ͑Δ͜ͱ͕Ͱ͖Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#schedulerΛ੾Γସ͑Δ
  29. Deep dive to Rx Scheduler - SchedulerΛ੾Γସ͑Δ - observeOn ▸

    ࢦఆͨ͠Ҏ߱ʹ࣮ߦ͞ΕΔOperatorͷSchedulerΛ੾Γସ͑ Δ http://reactivex.io/documentation/operators/images/observeOn.c.png
  30. Deep dive to Rx Scheduler - SchedulerΛ੾Γସ͑Δ - subscribeOn ▸

    Ұ൪্ྲྀͷObservable<Element>ىಈ͢ΔSchedulerΛ੾Γସ͑Δ ▸ ಺෦తʹ͸ࢦఆͨ͠Schedulerʹରͯ͠Observable<Element>Λsubscribe()͢ΔλεΫΛ௥Ճ͠ ͍ͯΔ ▸ Cold ObservableΛىಈ͢ΔSchedulerͷࢦఆ͸Ͱ͖Δ͕ɺHot Observable͸onNext(element: Element)ΛͦͷcontextͷSchedulerͰ࣮ߦ͢ΔͨΊɺࢦఆͯ͠΋ҙຯ͕ͳ͍ http://reactivex.io/documentation/operators/images/subscribeOn.c.png
  31. Deep dive to Rx Operator - ੜ੒ܥ - Observable.create Observable<E>.create(subscribe:

    (AnyObserver<E>) -> Disposable) -> Observable<E> αϯϓϧͰ΋͓ͳ͡ΈɺϒϩοΫ಺ͰAnyObserverʹରͯ͠஋Λൃߦ͍ͯ͘͠ObservableͷFactory http://reactivex.io/documentation/operators/images/create.c.png
  32. Deep dive to Rx Operator - ੜ੒ܥ - Observable.from Observable<E>.from(array:

    [E]) ഑ྻ͔ΒObservableΛੜ੒͢ΔFactory http://reactivex.io/documentation/operators/images/from.c.png
  33. Deep dive to Rx Operator - ੜ੒ܥ - Observable.interval Observable<E>.interval(period:

    RxTimeInterval, scheduler: SchedulerType) ࢦఆͨ͠RxTimeInterval(TimeInterval)͝ͱʹɺ0͔Βincrementͨ͠஋Λൃߦ͍ͯ͘͠Observableͷ Factory http://reactivex.io/documentation/operators/images/interval.c.png
  34. Deep dive to Rx Operator - ม׵ܥ - .map .map<R>(transform:

    E throws -> R) -> Observable<R> ElementΛR΁ม׵͢ΔOperator http://reactivex.io/documentation/operators/map.html
  35. Deep dive to Rx Operator - ม׵ܥ - .flatMap .flatMap<O

    : ObservableConvertibleType>(selector: E throws -> O) -> Observable<O.E> ElementΛड͚औΓɺ৽͍͠Observable<Element>Λޙଓʹྲྀ͢Operator http://reactivex.io/documentation/operators/images/flatMap.c.png
  36. Deep dive to Rx Operator - ม׵ܥ - .buffer .buffer(timeSpan:

    RxTimeInterval, count: Int, scheduler: SchedulerType) -> Observable<[E]> ࢦఆͨ͠timeSpan, countͷͲͪΒ͔ͷ࠷େ஋͝ͱʹόοϑΝϦϯάͨ͠஋Λ[Element]ͱͯ͠ޙଓʹྲྀ͢ Operator http://reactivex.io/documentation/operators/images/Buffer.png
  37. Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .filter .filter(predicate:

    E throws -> Bool) -> Observable<E> ElementΛR΁ม׵͢ΔOperator http://reactivex.io/documentation/operators/filter.html
  38. Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .throttle .throttle(dueTime:

    RxTimeInterval, scheduler: SchedulerType) -> Observable<E> ࢦఆͨ͠scheduler্ͰɺdueTimeؒͷElementΛؒҾ͘Operator http://reactivex.io/documentation/operators/debounce.html
  39. Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .distinctUntilChanged .distinctUntilChanged()

    -> Observable<E> ࠷ޙʹྲྀͨ͠ElementͱݱࡏͷElementͱΛൺֱ͠ɺࠩҟ͕͋Δ৔߹ͷΈޙଓʹྲྀͨ͢ΊͷOperator http://reactivex.io/documentation/operators/distinct.html ※URLઌͷαϯϓϧͰɺ্෦ͷετϦʔϜʹᶃ͕ଟ͘ग़Δόά͕͋Δ
  40. Deep dive to Rx Operator - ߹੒ܥ - Observable.of().merge Observable<Element>.of(ObservableConvertibleType…).merge()

    ෳ਺ͷObservable<Element>ΛϚʔδ͢Δ http://reactivex.io/documentation/operators/images/merge.png
  41. Deep dive to Rx Operator - ߹੒ܥ - Observable.zip Observable<E>.zip<O1:

    ObservableType, O2: ObservableType>(source1: O1, source2: O2, resultSelector: (O1.E, O2.E) throws -> E) -> Observable<E> ࢦఆͨ͠ෳ਺ͷObservable<Element>ʹྲྀΕΔॱ൪͕Ұகͨ͠Elementಉ࢜ʹରͯ͠ԋࢉΛߦ͍ɺ৽͠ ͍ElementΛޙଓʹྲྀ͢Operator http://reactivex.io/documentation/operators/zip.html
  42. Deep dive to Rx Operator - ߹੒ܥ - Observable.combineLatest Observable<E>.combineLatest<O1:

    ObservableType, O2: ObservableType>(source1: O1, source2: O2, resultSelector: (O1.E, O2.E) throws -> E) -> Observable<E> ࢦఆͨ͠ෳ਺ͷObservable<Element>ʹͯɺଞํͷ௚લͷElementͱݱࡏͷElementʹରͯ͠ԋࢉΛߦ ͍ɺ৽͍͠ElementΛޙଓʹྲྀ͢Operator http://reactivex.io/documentation/operators/combinelatest.html
  43. Deep dive to Rx Operator - ΤϥʔϋϯυϦϯάܥ - .catchError .catchError(handler:

    (Error) throws -> Observable<E>) blockͰErrorΛड͚औΓɺcatchՄೳͳErrorͰ͋Ε͹ޙଓͷͨΊͷObservable<Element>Λฦ͢ Operator catchෆՄೳͳ৔߹͸ɺblock಺Ͱrethrow͢ΔͱɺޙଓʹΤϥʔ͕ྲྀΕΔ http://reactivex.io/documentation/operators/images/Catch.png
  44. Deep dive to Rx Operator - ΤϥʔϋϯυϦϯάܥ - .catchErrorJustReturn .catchErrorJustReturn(E)

    -> Observable<E> Error͕ྲྀΕ͖ͯͨࡍʹɺࢦఆͨ͠஋Λޙଓ΁ྲྀ͢Operator ਤͳ͠
  45. Deep dive to Rx Operator - ΤϥʔϋϯυϦϯάܥ - .catchError .retry(maxAttemptCount:

    Int) Error͕ྲྀΕ͖ͯͨࡍʹɺ௚લ·ͰͷObservable<Element>ͰͷॲཧΛࢦఆճ਺͚ͩϦτϥΠ(࠶౓ subscribe())͢ΔOperator ࢦఆճ਺Λ௒͑ͨ৔߹ɺޙଓʹError͕ྲྀΕΔ http://reactivex.io/documentation/operators/images/retry.C.png
  46. Deep dive to Rx Operator - ϢʔςΟϦςΟܥ - .do .do(onNext:

    ((E) throws -> Void)?, onError: ((Error) throws -> Void)?, onCompleted: (() throws -> Void)?, onSubscribe: (() -> ())?, onDispose: (() -> ())?) -> Observable<E> onNext, onErrorͳͲͷ֤λΠϛϯάͰݺ͹ΕΔblockΛొ࿥͢ΔOperator ޙଓʹSubscriber͕1ͭ΋ͳ͍৔߹ɺ֤block͸ݺ͹Εͳ͍ http://reactivex.io/documentation/operators/images/do.c.png
  47. Deep dive to Rx Operator - ϢʔςΟϦςΟܥ - .delay .delay(dueTime:

    RxTimeInterval, scheduler: SchedulerType) ࢦఆͨ͠Πϯλʔόϧ࣌ؒ෼ɺElement͕ྲྀΕΔͷΛ஗Ԇͤ͞Δ http://reactivex.io/documentation/operators/delay.html
  48. Deep dive to Rx Operator - ϢʔςΟϦςΟܥ - .using .using(resourceFactory:

    () throws -> ResourceType, observableFactory: (ResourceType) throws -> Observable<E>) DisposableͳϦιʔε(ResourceType)ͱɺͦͷResourceTypeʹର͢ΔObservable<Element>ͷϑΝΫτ ϦΛ౉͢ͱɺsubscribe()ͷϥΠϑαΠΫϧͰϦιʔεͷੜ੒͔Βഁغ·Ͱߦ͏͜ͱ͕Ͱ͖ΔOperator http://reactivex.io/documentation/operators/images/using.c.png
  49. ࣮૷ܥͷ঺հ SwiftͰͷଞ࣮૷ܥ ▸ ReactiveCocoa ▸ ReactiveSwift: ίΞ࣮૷ ▸ ReactiveCocoa: UIKit޲͚ͷextension

    ▸ RxSwiftͱ͸Ϋϥε΍ϝιουͷ໊শʹେ͖ࠩ͘ҟ͕͋Δ ▸ Observable -> Signal, subscribe -> observe ▸ subscribeΛߦ͏ͨΊͷObserverͱ͍͏Ϋϥε ▸ Hot, Cold ObservableΛͦΕͧΕɺSignal, SignalProducerͱ͍͏ܕ Ͱѻ͑ΔΑ͏ʹ͍ͯ͠Δ
  50. ࣮૷ܥͷ঺հ SwiftͰͷଞ࣮૷ܥ ▸ ReactiveKit ▸ ReactiveKit: ίΞ࣮૷ ▸ Bond: UIKit޲͚ͷextension

    ▸ ݩʑ͸Swift Bondͱ͍͏ϑϨʔϜϫʔΫ͕ͩͬͨɺίΞ࣮ ૷ͱUI Bindingͷextension͕෼཭͠ࠓͷߏ੒ʹͳͬͨ ▸ ࣮૷ܗଶ͸ReactiveSwiftʹ͍͕ۙɺScheduler͕ͳ͍(࣮ߦ ͢ΔDispatchQueue͸ࢦఆͰ͖Δ)ͳͲྑ͘΋ѱ͘΋࠷খݶ
  51. ·ͱΊ ▸ RxΛ࢖͏ͱɺ࣌ܥྻͷΠϕϯτ͕࿈ଓͰൃੜ͢ΔΑ͏ͳσʔλू߹Λએݴత ʹѻ͑Δ ▸ ֶशίετ͸ͦΕͳΓʹߴ͍ ▸ Observableͷಛੑ ▸ ߪಡͷഁغͱϥΠϑαΠΫϧ

    ▸ Operator΁ͷཧղͱ૊Έ߹Θͤ ▸ Schedulerͷ੾Γସ͑ ▸ શͯRxͰ૊ΈཱͯΔඞཁ͸ͳ͍ͷͰɺUI΍HTTP RequestͳͲ͔Β·ͣ͸࢖ ͍࢝ΊͯΈΔͷ͕Φεεϝ ▸ ࠓࢿྉͰ঺հͨ͠Ҏ֎ʹɺRxSwiftʹ͸DriverͳͲͷػೳ΋͋Δ
  52. ࢀߟ ▸ Rx (Reactive Extensions) - Home ▸ ReactiveX ▸

    ࢿྉ಺ͷMarble Diagrams͸ɺReactiveXͷίϯςϯπͰ ͋ΓɺCreative Commons Attribution 3.0ͷϥΠηϯεʹ ΑΓอޢ͞Ε͍ͯ·͢ ▸ Reactive Extensionsͷ͸͡Ί͔ͨ - ͔͖ͣͷBlog@hatena