Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
はじめてのRxSwift体験記
Search
haptaro
November 17, 2016
Programming
3
640
はじめてのRxSwift体験記
第3回RxSwift勉強会@Sansanの発表資料になります
haptaro
November 17, 2016
Tweet
Share
More Decks by haptaro
See All by haptaro
通信環境が不安定でも心地よい体験を
kotaro
0
90
アニメーション実践入門
kotaro
3
570
iOSアプリ開発にもDIツールを!
kotaro
5
1.2k
Swiftで気持ち良く開発したアプリを気持ち良くSubmitする
kotaro
0
7.2k
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
970
RubyLSPのマルチバイト文字対応
notfounds
0
120
Tauriでネイティブアプリを作りたい
tsucchinoko
0
370
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
900
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
230
CSC509 Lecture 12
javiergs
PRO
0
160
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
WebフロントエンドにおけるGraphQL(あるいはバックエンドのAPI)との向き合い方 / #241106_plk_frontend
izumin5210
4
1.4k
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
630
Featured
See All Featured
How to train your dragon (web standard)
notwaldorf
88
5.7k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
900
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Embracing the Ebb and Flow
colly
84
4.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
720
Transcript
͡ΊͯͷRxSwiftମݧه @haptaro
• ඌ ଠ • Sansanגࣜձࣾ Eightࣄۀ෦ • iOSΞϓϦΤϯδχΞ (ΞϧόΠτ)
RxSwift
ΞδΣϯμ • ཧղ͕͔ͬͨ͠ͱ͜Ζ4બ • ·ͱΊ
ཧղ͕͔ͬͨ͠ͱ͜Ζ4બ • DisposeBag • shareReplay • combineLatest • flatMapLatest
DisposeBag
ຖճετϦʔϜͷ࠷ޙʹ͍͍ͭͯΔ ۚڕͷฅΈ͍ͨͳ͍ͭ͜…
disposeBag DisposableΛೖΕ͓ͯ͘ାͷΑ͏ͳͷ RxSwiftͰͷϝϞϦཧ ※subscribebindToDisposableΛฦ͢
disposeBagΛϓϩύςΟʹ͍࣋ͬͯΔΦϒδΣΫτͷ deallocͷλΠϛϯάͰାͷதΛഁغͯ͘͠ΕΔ ※ݫີʹାʹೖΕͨDisposable֤ʑͰdispose()͕ݺΕΔ
shareReplay
·ͨۚڕͷฅΈ͍ͨʹ͍ͭͯΔ…
Hot / Cold • Cold Observableɾɾɾsubscribe͢Δ·Ͱ࣮ߦ ͞Εͳ͍ɻ΄ͱΜͲͷΦϖϨʔλCold • Hot ObservableɾɾɾذͰ͖ɺు͍ͨΠϕϯ
τ֤ObserverͰڞ༗͞ΕΔ
Cold ObservableذͰ͖ͳ͍ Cold Cold Observer Observer Cold Cold Cold Cold
Hot ObservableذͰ͖Δ Cold Cold Hot Observer Observer
Observer Observable
shareReplay HotมΦϖϨʔλ
Observer Observer Observer Observer Observer Observable
combineLatest
2ͭͷObservableΛҾͱͯ͠ड͚औ͍ͬͯΔ͍ͭ͜… ͦͯ͠LatestͬͯͳΜ…
Rxʹ͓͚ΔʮLatestʯ Observable͔Βు͔Εͨ ʮ࠷৽ʯͷ ͍ͭ͜ʂ ࠷৽
ෳͷObservable͕ు͍ͨ࠷ ৽ͷΛͭͳ͍͛ͨͱ͖ʹ͏
flatMapLatest
ΫϩʔδϟͰObservableΛฦ͍ͯ͠Δͷ͔…ʁ ͜ΕObservableͱObservableΛͭͳ͍͛ͯΔͷ͔…ʁ
flatMapΛཧղ͢Δʹ·ͣ
map
1 2 3 4 2 4 6 8 .map {
$0 * 2 }
flatMap
mapػೳʹՃ͑ͯɺObservableΛണ͕ ͯ͘͠ΕΔ(ۉͯ͘͠ΕΔ)Α͏ͳͷ
flatMap = map + flatten ※flatMapLatest = map + switchLatest
getText() -> Observable<String> use(text: String) -> Observable<Void> 2ͭͷؔΛߟ͑Δ…
getTextؔͰಘͨจࣈྻΛ useؔͰ͍͍ͨ…
mapͩͱ Observable<String>
mapͩͱ Observable<String> Observable<Observable<String>>
flatMapͩͱ Observable<String>
flatMapͩͱ Observable<String> Observable<Observable<String>>
flatMapͩͱ Observable<String> Observable<Observable<String>> Observable<String>
getText().flatMap { text return use(text) }
͜͜Ͱٙʹ…
flatMapLatestͳΜ͔Θ͔͚ͬͨͲɺ combineLatestObservableΛͭͳ͛Δͱ͔ͳΜ ͱ͔… ͍͚ͱ͔ϙΠϯτΓ͍ͨ…
ϙΠϯτ • combineLatestɾɾɾෳͷObservable͕ు͍ͨ ࠷৽ͷΛͭͳ͍͛ͨͱ͖ • flatMapLatestɾɾɾʮObservableΛฦ͢ॲཧʯ ͷʮ݁ՌʯΛʮॱংʯΛؾʹͯͭ͠ͳ͍͛ͨͱ ͖
·ͱΊ • ࠷ॳͬ͞ͺΓ͕ͩͬͨঃʑʹݟ͑ͯ͘ΔͷͰ׳Εͷ෦͕େ͖ ͍ • ObservableͱObserver͕Կ͔Λߟ͑ɺΦϖϨʔλͰՃ͍ͯ͠ ͘ࡍܕΛҙࣝ͢Δ͜ͱ͕ॏཁ • ֓೦ͷཧղεϨουͷཧͳͲΛ͔ͬ͠Γ͍ͯ͠ͳ͍ͱύϑΥʔ Ϛϯε͕Լ͕ͬͨΓɺҙਤ͠ͳ͍ಈ͖Λ͢Δةݥੑ͋Δ
• RxSwiftͷجૅతͳ෦ཧղͭͭ͋͠ΔͷͰɺࠓޙ࣮ࡍʹϓ ϩμΫτͰ͍ͳ͕ΒֶΜͰ͍͖͍ͨ
ཧղͷཱͬͨࢿྉ • RxSwift։ൃΛͲ͏ม͔͑ͨ https://speakerdeck.com/ishkawa/rxswifthakai-fa-wodoubian-etaka • RxExample͔ΒֶͿʂRxSwift https://speakerdeck.com/kazu0620/rxexamplekaraxue-bu-rxswift • ࠓͦ͜ཧղ͢Δ Hot
/ Cold http://www.slideshare.net/yukitakahashi3139241/hot-cold • shareReplayΛͪΌΜͱॻ͍͓ͯߦّྑ͘ετϦʔϜΛߪಡ͠Α͏ http://qiita.com/kazu0620/items/bde4a65e82a10bd33f88 • RxSwiftͷobserveOnͱsubscribeOnΛཧղ͢Δ https://speakerdeck.com/bricklife/rxswiftfalseobserveontosubscribeonwoli-jie-suru
Happy RxSwift Life!