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
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
カスタムしながら理解するGraphQL Connection
yanagii
1
1.3k
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
23k
Importmapを使ったJavaScriptの 読み込みとブラウザアドオンの影響
swamp09
4
1.3k
ECSのサービス間通信 4つの方法を比較する 〜Canary,Blue/Greenも添えて〜
tkikuc
11
2.3k
go.mod、DockerfileやCI設定に分散しがちなGoのバージョンをまとめて管理する / Go Connect #3
arthur1
10
2.4k
Content Security Policy入門 セキュリティ設定と 違反レポートのはじめ方 / Introduction to Content Security Policy Getting Started with Security Configuration and Violation Reporting
uskey512
1
440
[PyCon Korea 2024 Keynote] 커뮤니티와 파이썬, 그리고 우리
beomi
0
120
Golang と Erlang
taiyow
8
1.9k
GCCのプラグインを作る / I Made a GCC Plugin
shouth
1
150
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
230
Dev ContainersとGitHub Codespacesの素敵な関係
ymd65536
1
130
Featured
See All Featured
Docker and Python
trallard
40
3.1k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.2k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Speed Design
sergeychernyshev
24
580
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
GraphQLとの向き合い方2022年版
quramy
43
13k
Why Our Code Smells
bkeepers
PRO
334
57k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Practical Orchestrator
shlominoach
186
10k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.8k
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!