Lock in $30 Savings on PRO—Offer Ends Soon! ⏳
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
97
アニメーション実践入門
kotaro
3
610
iOSアプリ開発にもDIツールを!
kotaro
5
1.3k
Swiftで気持ち良く開発したアプリを気持ち良くSubmitする
kotaro
0
7.3k
Other Decks in Programming
See All in Programming
WebRTC と Rust と8K 60fps
tnoho
2
740
All(?) About Point Sets
hole
0
230
2025 컴포즈 마법사
jisungbin
0
160
乱雑なコードの整理から学ぶ設計の初歩
masuda220
PRO
32
15k
しっかり学ぶ java.lang.*
nagise
1
460
社内オペレーション改善のためのTypeScript / TSKaigi Hokuriku 2025
dachi023
1
130
S3 VectorsとStrands Agentsを利用したAgentic RAGシステムの構築
tosuri13
3
120
モダンJSフレームワークのビルドプロセス 〜なぜReactは503行、Svelteは12行なのか〜
fuuki12
0
140
Full-Cycle Reactivity in Angular: SignalStore mit Signal Forms und Resources
manfredsteyer
PRO
0
150
Feature Flags Suck! - KubeCon Atlanta 2025
phodgson
0
180
Duke on CRaC with Jakarta EE
ivargrimstad
0
300
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.4k
Writing Fast Ruby
sferik
630
62k
The Cult of Friendly URLs
andyhume
79
6.7k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
253
22k
Optimizing for Happiness
mojombo
379
70k
BBQ
matthewcrist
89
9.9k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.2k
The Language of Interfaces
destraynor
162
25k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
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!