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
660
3
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
はじめてのRxSwift体験記
第3回RxSwift勉強会@Sansanの発表資料になります
haptaro
November 17, 2016
More Decks by haptaro
See All by haptaro
通信環境が不安定でも心地よい体験を
kotaro
0
110
アニメーション実践入門
kotaro
3
640
iOSアプリ開発にもDIツールを!
kotaro
5
1.4k
Swiftで気持ち良く開発したアプリを気持ち良くSubmitする
kotaro
0
7.3k
Other Decks in Programming
See All in Programming
PyConJP2026_wat_Python × Signal Processing: How to Draw Pictures with Sound Using Spectrogram Art
wat
0
620
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
330
業務時間外もAIに働いてもらう話
colorful12
3
9.4k
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
130
MySQLとPostgreSQLって何が違うの?
akagami
0
150
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
410
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
110
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.8k
DynamoDBの基礎を振り返りながらベクトル検索機能を理解する
musan
3
250
[PyCon KR 2026] More Variants, More Diversity for AI Accelerators
achimnol
0
130
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
2
190
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
370
Featured
See All Featured
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
45k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.9k
The Curse of the Amulet
leimatthew05
2
14k
Designing for Performance
lara
611
70k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
400
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
230
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Building Applications with DynamoDB
mza
96
7.2k
Site-Speed That Sticks
csswizardry
13
1.5k
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!