Share
Embed
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
Annual Pro sale · Save $30
Have presentations of your own?
Share with private links, password protection, and more control over your work.
Transcript
83 slides
-
ΞδΣϯμ ▸ Reactive Extensionͱ ▸ αϯϓϧΞϓϦ ▸ Deep dive to
Rx ▸ ϥΠϒϥϦ ※αϯϓϧίʔυͰ༻͢Δݴޠ, ࣮ܥSwift3.0.1 + RxSwift(3.0.0-rc.1)Λ༻͢Δ ※αϯϓϧίʔυ͕େྔʹͳͬͨͷͰɺαϯϓϧίʔυͱ߹ΘͤͯӾཡΛਪ͢Δ -
Reactive Extensionͱ Rx = Observables + LINQ + Schedulers ▸
Observables: Observer PatternͰ࣮͞Εͨ࣌ܥྻͰൃੜ͢Δσʔλू ߹ ▸ LINQ: ओʹ.NET FrameworkͰར༻Մೳͳσʔλू߹ʹରͯ͠ΫΤϦϯ άΛߦ͏Έ(RxͰOperatorͱݺΕΔ) ▸ Schedulers: ͍ͭ, Ͳ͜ͰΛൃੜ, ॲཧ, ߪಡ͢Δ͔Λѻ͏εέδϡʔϥ ҙͷεέδϡʔϥͰɺ࣌ܥྻͰൃੜ͢Δσʔλू߹(Stream)ʹ ରͯ͠ΫΤϦΛൃߦ͠ɺ݁ՌΛߪಡ͢Δ ͜ͱ͕Ͱ͖ΔΈ -
Reactive Extensionͱ ͜͜·Ͱͷ·ͱΊ ▸ Rx = Observables + LINQ +
Schedulers ▸ ࣌ܥྻͰൃੜ͢Δσʔλू߹ΛετϦʔϜͱݺͿ ▸ Rxͷಈ࡞Marble DiagramsͰද͞ΕΔ -
αϯϓϧΞϓϦ Github Repository Search APIͰݕࡧΛߦ͍ɺ݁ՌΛදࣔ͢Δ ▸ ೖྗจࣈΛݕࡧϫʔυͱͯ͠ɺGithubͷRepository Search APIΛ call͢Δ
▸ Ϩεϙϯεσʔλ͔ΒɺϦϙδτϦ໊ͷҰཡΛऔಘ͠ɺ TableViewʹදࣔ͢Δ ▸ ΤϥʔͳͲͷҟৗܥҰ୴ߟྀ͠ͳ͍ -
αϯϓϧΞϓϦ Rx͋ΓͰߟ͑ͯΈΔ - ֓೦ฤ ▸ UISearchBarͷೖྗΛObservableͰड͚Δ ▸ .throttle() OperatorͰೖྗΛؒҾ͘ ▸
.distinctUntilChanged() OperatorͰॏෳೖྗΛࢭ ▸ ೖྗΛURLSession.rx.json(url)ͰϦΫΤετ͠ɺ݁ՌͷObservableΛड͚औΔ ▸ ݁ՌͷετϦʔϜΛtableViewʹbind͠ɺObservableͷ݁ՌʹΑͬͯ tableView͕ߋ৽͞ΕΔΑ͏ʹ͢Δ ObservableͱOperator(֤छૢ࡞Λߦ͏ϝιου)Λ༻͍Δͱ ͜ͷΑ͏ʹߟ͑ɺ࣮Ͱ͖Δ -
Deep dive to Rx Observableͷੜͱߪಡ(Observable.create) - Τϥʔ ObservableΛੜ͠ɺObserverʹରͯ͠ͱΤϥʔΛൃߦɺσʔλΛߪಡ ͢Δ αϯϓϧίʔυ:
https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#ΤϥʔΛ ൃੜͤ͞Δ -
Deep dive to Rx Observableͷੜͱߪಡ(Observable.create) - ·ͱΊ ▸ Observable<Element> ▸
Elementܕͷʹରͯ͠ɺΫΤϦ, ߪಡΛߦ͏ͨΊͷΫϥε (جఈprotocolObservableConvertibleType) ▸ Streamͷ࣮ମ ▸ ༷ʑͳOperatorΛඋ͑Δ ▸ ΫΤϦ: map, flatMap, take, filter… ▸ ߪಡ: subscribe, bindTo… -
Deep dive to Rx Observableͷੜͱߪಡ(Observable.create) - ·ͱΊ ▸ AnyObserver<Element> ▸
֤छ, ΠϕϯτΛൃߦ͢ΔͨΊͷΫϥε(جఈprotocol ObserverType) ▸ onNext(element: Element), onError(error: Error), onCompleted()ͷϝιουΛඋ͑Δ -
Deep dive to Rx Observableͷੜͱߪಡ(Observable.create) - ·ͱΊ ▸ Disposable ▸
ߪಡͷഁغΛߦ͏ͨΊͷϝιουΛఆٛͨ͠protocol ▸ subscribe()ͷΓDisposableͰɺdispose()Λcall͢ Δ͜ͱʹΑΓߪಡͷഁغΛߦ͏͜ͱ͕Ͱ͖Δ -
Deep dive to Rx Observableͷੜͱߪಡ(Observable.create) - ·ͱΊ ▸ ObservableͷϥΠϑαΠΫϧ ▸
onError(error: Error)ͱonCompleted()͕௨͞Εͨ Observable<Element>ྃঢ়ଶʹͳΓɺͦͷޙ, Π ϕϯτΛྲྀ͢͜ͱͰ͖ͳ͍ -
Deep dive to Rx Observableͷੜͱߪಡ(PublishSubject) - ·ͱΊ ▸ PublishSubject<Element> ▸
ObservableType, ObserverTypeͷͲͪΒͷੑ࣭උ͑ͨΫϥ ε(= , Πϕϯτͷൃੜ, ߪಡΛͲͪΒߦ͑Δ)Λ”Subject” ͱݺͿ ▸ PublishSubject<Element>લड़ͷMarble Diagramsͷ௨ Γɺon(Next|Error|Completed)Λߦ͏ͱɺͦͷ࣌Ͱͷશͯ ͷSubscriberʹͦͷ௨Λߦ͏Subject ▸ “Subject”ʹଞʹReplaySubject, VariableͳͲ͕͋Δ -
Deep dive to Rx Observableͷੜͱߪಡ(PublishSubject) - ·ͱΊ ▸ DisposeBag ▸
DisposeBagͷΠϯελϯε͕dealloc͞ΕΔࡍʹɺొ͞ ΕͨDisposableͳΠϯελϯεΛશͯdispose()͢ΔΫϥ ε ▸ ৄࡉޙड़ -
Deep dive to Rx Observableͷੜͱߪಡ ▸ Observable.create: Cold Observable ▸
PublishSubject: Hot Observable -
Deep dive to Rx Hot, Cold Observable - ͱ ObservableʹɺHot,
Cold ͱ͍͏ 2ͭͷੑ࣭͕͋Γɺ֤OperatorඞͣͲͪΒ͔ͷੑ࣭Λඋ͑ͨ ObservableΛੜ͢Δ -
Deep dive to Rx Hot, Cold Observable - ͱ Cold
Observable Hot Observable ͷൃߦ subscribe()࣌ ਵ࣌ Streamͷذ ͠ͳ͍ ͢Δ ্ྲྀʹର͢ΔӨڹ ͳ͠ ্ྲྀͷCold Observableͷ Λཁٻ͢Δ -
Deep dive to Rx Hot, Cold Observable - ͷൃߦ, Streamͷذ
Observable.createͷྫʹɺͷൃߦ࣌ؒΛՃ͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#observablecreateͷྫʹͷ ൃߦ࣌ؒΛՃ͢Δ ▸ subscribe()Λߦ͏(Observer͕͞ΕΔ)͝ͱʹɺ͕ൃߦ ͞ΕΔ ▸ subscribe()ΛߦͬͨࡍʹɺStream͕Ͱ͖Δ ▸ ͭ·Γɺ1ͭͷStreamذ͠ͳ͍ -
Deep dive to Rx Hot, Cold Observable - ͷൃߦ, Streamͷذ
PublishSubjectͷྫʹɺͷൃߦ࣌ؒΛՃ͢Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#publishsubjectͷྫʹͷൃ ߦ࣌ؒΛՃ͢Δ ▸ subscribe()Λߦ͏(Observer͕͞ΕΔ)͔Ͳ͏͔ʹݶΒͣɺ ͕ൃߦ͞ΕΔ ▸ subscribe()ΛߦΘͳ͘ͱɺStream͕Ͱ͖Δ ▸ ͭ·Γɺ1ͭͷStream͕ذ͢Δ -
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)) -
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"Λ؍ଌͰ͖ͳ͍) -
Deep dive to Rx Hot, Cold Observable - ·ͱΊ Cold
Observable Hot Observable ͷൃߦ subscribe()࣌ ਵ࣌ Streamͷذ ͠ͳ͍ ͢Δ ্ྲྀʹର͢ΔӨڹ ͳ͠ ্ྲྀͷCold Observableͷ Λཁٻ͢Δ Observable<Element>Λsubscribe()͢Δ߹ʹɺͦͷੑ࣭ΛΑ͘ݟ ۃΊΔඞཁ͕͋Δ -
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ͦΕͧΕʹɺಉ͡ ͕ྲྀΕ͍ͯΔʹ -
Deep dive to Rx Hot, Cold Observable - ิ -
shareReplay ྫ͑ɺViewModelͷΑ͏ͳclass͔ΒViewControllerͳͲͷ֎෦ʹରͯ͠ Observable<Element>Λఏڙ͢Δ߹ʹɺViewModelࣗʹͷ Observable<Element>ͷSubscribersubscribe()ͷλΠϛϯάΛ੍ޚ͢Δ͜ͱ ͍͠ ͦ͏͍ͬͨ߹ʹɺCold, Hot Observable͍ͣΕͷ߹ `observable.shareReplay(1)`ͱ͔ͯ͠Βఏڙ͢Δ͜ͱͰ ▸ Cold Observable: લͷHot Observable, ͘͠ൃੜݩ·Ͱͷ Operatorͷॲཧ͕Subscriber͝ͱʹൃੜ͢ΔͷΛࢭ͢Δ ▸ Hot Observable: SubscriberۙͷΛඞͣߪಡ͢Δ͜ͱ͕Ͱ͖Δ -
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)͞Ε͍ͯΔ -
Deep dive to Rx Disposable - ͱ subscribe(), bindTo()ͳͲͷϝιουͷΓ .dispose()ͱ͍͏ϝιουΛ༻͍ͯɺ
▸ ߪಡഁغͷཁٻ ▸ ߪಡͷ࣮͕ॴଐ͢ΔίϯςΩετͷϥΠϑαΠΫϧ ͷλΠϛϯάͰɺߪಡΛഁغ͢Δ ߪಡͷഁغΛଵͬͨ߹ɺBAD ACCESSϝϞϦϦʔΫ͕ൃੜ͢ ΔՄೳੑ͕͋Δ -
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()`͢Δ -
Deep dive to Rx Scheduler - Serial vs Concurrent Scheduler
▸ Serial Schedulers: ॱ࣍ॲཧ ▸ Concurrent Schedulers: ฒྻॲཧ -
Deep dive to Rx Scheduler - Serial Scheduler https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#serial-scheduler ▸
SerialDispatchQueueSchedulerΛ༻͍ͯɺ DispatchQueue.global()Ͱॱ࣮࣍ߦ͞ΕΔSerial SchedulerΛੜ ▸ subscribe()ͷ࣮ߦ͕ɺએݴॱʹߦΘΕ͍ͯΔ -
Deep dive to Rx Scheduler - Serial Scheduler https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#concurrent-scheduler ▸
ConcurrentDispatchQueueSchedulerΛ༻͍ͯɺ DispatchQueue.global()Ͱฒྻ࣮ߦ͞ΕΔSerial SchedulerΛੜ ▸ subscribe()ͷ࣮ߦ͕ɺผʑͷεϨουͰฒྻʹߦΘΕ͍ͯΔ -
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 -
Deep dive to Rx Scheduler - SchedulerΛΓସ͑Δ ▸ observeOn, subscribeOnͱ͍͏OperatorͰSchedulerΛ
Γସ͑Δ͜ͱ͕Ͱ͖Δ https://gist.github.com/dameleon/9fc3178aaba1f695455234af40730a03#schedulerΛΓସ͑Δ -
Deep dive to Rx Scheduler - SchedulerΛΓସ͑Δ - observeOn ▸
ࢦఆͨ͠Ҏ߱ʹ࣮ߦ͞ΕΔOperatorͷSchedulerΛΓସ͑ Δ http://reactivex.io/documentation/operators/images/observeOn.c.png -
Deep dive to Rx Scheduler - SchedulerΛΓସ͑Δ - subscribeOn ▸
Ұ൪্ྲྀͷObservable<Element>ىಈ͢ΔSchedulerΛΓସ͑Δ ▸ ෦తʹࢦఆͨ͠Schedulerʹରͯ͠Observable<Element>Λsubscribe()͢ΔλεΫΛՃ͠ ͍ͯΔ ▸ Cold ObservableΛىಈ͢ΔSchedulerͷࢦఆͰ͖Δ͕ɺHot ObservableonNext(element: Element)ΛͦͷcontextͷSchedulerͰ࣮ߦ͢ΔͨΊɺࢦఆͯ͠ҙຯ͕ͳ͍ http://reactivex.io/documentation/operators/images/subscribeOn.c.png -
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 -
Deep dive to Rx Operator - ੜܥ - Observable.from Observable<E>.from(array:
[E]) ྻ͔ΒObservableΛੜ͢ΔFactory http://reactivex.io/documentation/operators/images/from.c.png -
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 -
Deep dive to Rx Operator - มܥ - .map .map<R>(transform:
E throws -> R) -> Observable<R> ElementΛRม͢ΔOperator http://reactivex.io/documentation/operators/map.html -
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 -
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 -
Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .filter .filter(predicate:
E throws -> Bool) -> Observable<E> ElementΛRม͢ΔOperator http://reactivex.io/documentation/operators/filter.html -
Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .throttle .throttle(dueTime:
RxTimeInterval, scheduler: SchedulerType) -> Observable<E> ࢦఆͨ͠scheduler্ͰɺdueTimeؒͷElementΛؒҾ͘Operator http://reactivex.io/documentation/operators/debounce.html -
Deep dive to Rx Operator - ϑΟϧλϦϯάܥ - .distinctUntilChanged .distinctUntilChanged()
-> Observable<E> ࠷ޙʹྲྀͨ͠ElementͱݱࡏͷElementͱΛൺֱ͠ɺࠩҟ͕͋Δ߹ͷΈޙଓʹྲྀͨ͢ΊͷOperator http://reactivex.io/documentation/operators/distinct.html ※URLઌͷαϯϓϧͰɺ্෦ͷετϦʔϜʹᶃ͕ଟ͘ग़Δόά͕͋Δ -
Deep dive to Rx Operator - ߹ܥ - Observable.of().merge Observable<Element>.of(ObservableConvertibleType…).merge()
ෳͷObservable<Element>ΛϚʔδ͢Δ http://reactivex.io/documentation/operators/images/merge.png -
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 -
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 -
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 -
Deep dive to Rx Operator - ΤϥʔϋϯυϦϯάܥ - .catchErrorJustReturn .catchErrorJustReturn(E)
-> Observable<E> Error͕ྲྀΕ͖ͯͨࡍʹɺࢦఆͨ͠Λޙଓྲྀ͢Operator ਤͳ͠ -
Deep dive to Rx Operator - ΤϥʔϋϯυϦϯάܥ - .catchError .retry(maxAttemptCount:
Int) Error͕ྲྀΕ͖ͯͨࡍʹɺલ·ͰͷObservable<Element>ͰͷॲཧΛࢦఆճ͚ͩϦτϥΠ(࠶ subscribe())͢ΔOperator ࢦఆճΛ͑ͨ߹ɺޙଓʹError͕ྲྀΕΔ http://reactivex.io/documentation/operators/images/retry.C.png -
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 -
Deep dive to Rx Operator - ϢʔςΟϦςΟܥ - .delay .delay(dueTime:
RxTimeInterval, scheduler: SchedulerType) ࢦఆͨ͠Πϯλʔόϧ࣌ؒɺElement͕ྲྀΕΔͷΛԆͤ͞Δ http://reactivex.io/documentation/operators/delay.html -
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 -
࣮ܥͷհ ReactiveXܥ http://reactivex.io/languages.html SwiftͰRxSwiftͰ͋ΓɺߏҎԼͷΑ͏ʹͳ͍ͬͯΔ ▸ RxSwift: ίΞ࣮ ▸ RxCocoa: UIKit͚ʹRxΛద༻͢Δextension
▸ RxTest, RxBlocking: ςετίʔυ͚ͷRx࣮, ֦ு -
࣮ܥͷհ SwiftͰͷଞ࣮ܥ ▸ ReactiveCocoa ▸ ReactiveSwift: ίΞ࣮ ▸ ReactiveCocoa: UIKit͚ͷextension
▸ RxSwiftͱΫϥεϝιουͷ໊শʹେ͖ࠩ͘ҟ͕͋Δ ▸ Observable -> Signal, subscribe -> observe ▸ subscribeΛߦ͏ͨΊͷObserverͱ͍͏Ϋϥε ▸ Hot, Cold ObservableΛͦΕͧΕɺSignal, SignalProducerͱ͍͏ܕ Ͱѻ͑ΔΑ͏ʹ͍ͯ͠Δ -
࣮ܥͷհ SwiftͰͷଞ࣮ܥ ▸ ReactiveKit ▸ ReactiveKit: ίΞ࣮ ▸ Bond: UIKit͚ͷextension
▸ ݩʑSwift Bondͱ͍͏ϑϨʔϜϫʔΫ͕ͩͬͨɺίΞ࣮ ͱUI Bindingͷextension͕͠ࠓͷߏʹͳͬͨ ▸ ࣮ܗଶReactiveSwiftʹ͍͕ۙɺScheduler͕ͳ͍(࣮ߦ ͢ΔDispatchQueueࢦఆͰ͖Δ)ͳͲྑ͘ѱ͘࠷খݶ -
࣮ܥͷհ Ͳͷ࣮ܥΛબͿ͔ʁ ▸ SwiftͰݴ֤࣮͑ͱੵۃతʹcommit͞Ε͍ͯΔ ▸ Ұ൪ΘΕ͍ͯΔ&ଟݴޠؒͰͷίϯςΩετεΠον͕গ ͳ͍&υΩϡϝϯτ͕ଟ͍ͷ RxSwift ▸ ͨͩ͠ɺͦͷϑϨʔϜϫʔΫ͕େ͖͍ͷ
RxSwift ▸ ΞϓϦͷੑ࣭ʹΑͬͯબࢶͱͳΔཁૉ͕มΘΔͷͰɺҰ ֓ʹݴ͑ͳ͍ -
·ͱΊ ▸ RxΛ͏ͱɺ࣌ܥྻͷΠϕϯτ͕࿈ଓͰൃੜ͢ΔΑ͏ͳσʔλू߹Λએݴత ʹѻ͑Δ ▸ ֶशίετͦΕͳΓʹߴ͍ ▸ Observableͷಛੑ ▸ ߪಡͷഁغͱϥΠϑαΠΫϧ
▸ OperatorͷཧղͱΈ߹Θͤ ▸ SchedulerͷΓସ͑ ▸ શͯRxͰΈཱͯΔඞཁͳ͍ͷͰɺUIHTTP RequestͳͲ͔Β·ͣ ͍࢝ΊͯΈΔͷ͕Φεεϝ ▸ ࠓࢿྉͰհͨ͠Ҏ֎ʹɺRxSwiftʹDriverͳͲͷػೳ͋Δ -
ࢀߟ ▸ Rx (Reactive Extensions) - Home ▸ ReactiveX ▸
ࢿྉͷMarble DiagramsɺReactiveXͷίϯςϯπͰ ͋ΓɺCreative Commons Attribution 3.0ͷϥΠηϯεʹ ΑΓอޢ͞Ε͍ͯ·͢ ▸ Reactive Extensionsͷ͡Ί͔ͨ - ͔͖ͣͷBlog@hatena