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
今日こそ理解するHot変換@社内RxSwift勉強会
Search
ukitaka
July 18, 2016
Programming
4
840
今日こそ理解するHot変換@社内RxSwift勉強会
今日こそ理解するHot変換
ukitaka
July 18, 2016
Tweet
Share
More Decks by ukitaka
See All by ukitaka
CSの生産性改善を支える分析環境 Mercari CS/CRE Tech Talk #1
ukitaka
1
2.7k
switchのexhaustiveness/redundancy チェック 理論と実装 わいわいswiftc #8 @ukitaka
ukitaka
0
190
SwiftのDemanglerを書く @ わいわいswiftc番外編
ukitaka
0
440
Swiftの型システムに入門する - iOSDC Japan 2018
ukitaka
10
6.8k
Responder Chainを使って コードをスッキリさせたい - 第1回 HAKATA.swift
ukitaka
6
1.4k
理論から入門するswift/lib/Sema - わいわいswiftc #1
ukitaka
5
1.6k
Realmの処理を再利用可能かつ合成可能にする
ukitaka
0
910
マルチスレッドRxSwift @ 社内RxSwift勉強会
ukitaka
5
1.2k
今日こそ理解するHot / Cold @社内RxSwift勉強会
ukitaka
14
2.7k
Other Decks in Programming
See All in Programming
eBPF Updates (March 2025)
kentatada
0
130
私の愛したLaravel 〜レールを超えたその先へ〜
kentaroutakeda
12
3.6k
アプリを起動せずにアプリを開発して品質と生産性を上げる
ishkawa
0
370
Return of the Full-Stack Developer
simas
PRO
1
320
Windows版PHPのビルド手順とPHP 8.4における変更点
matsuo_atsushi
0
370
生成AIの使いどころ
kanayannet
0
100
マルチアカウント環境での、そこまでがんばらない RI/SP 運用設計
wa6sn
0
600
JavaOne 2025: Advancing Java Profiling
jbachorik
1
320
AtCoder Heuristic First-step Vol.1 講義スライド
terryu16
2
1k
エンジニア未経験が最短で戦力になるためのTips
gokana
0
220
安全に倒し切るリリースをするために:15年来レガシーシステムのフルリプレイス挑戦記
sakuraikotone
5
2.3k
Modern Angular:Renovation for Your Applications @angularDays 2025 Munich
manfredsteyer
PRO
0
140
Featured
See All Featured
Product Roadmaps are Hard
iamctodd
PRO
52
11k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Done Done
chrislema
183
16k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
30
1.1k
A better future with KSS
kneath
238
17k
Being A Developer After 40
akosma
90
590k
Into the Great Unknown - MozCon
thekraken
36
1.7k
Rails Girls Zürich Keynote
gr2m
94
13k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
How STYLIGHT went responsive
nonsquared
99
5.4k
Transcript
ࠓͦ͜ཧղ͢Δ Hotม @ࣾRxSwiftษڧձ
https://speakerdeck.com/ukitaka/cold-at-she-nei-rxswiftmian-qiang-hui લճͷଓ͖
Hotม
Cold → Hot
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected
·͊ͱΓ͋͑ͣͬͯΈΔ͔
publish()
Question1 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
͜Μͳͷ؆୯͡ΌΜʂ 1,2,3Ͱ͠ΐʂ
͜Μͳͷ؆୯͡ΌΜ Sequence Map Hot subscribe Քಇ
͜Μͳͷ؆୯͡ΌΜ Sequence Map Hot subscribe Քಇ
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
!?
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected ؚΈͷ͋Δݴ͍ํ
Hotม ϙΠϯτͦͷ1 ConnectableObservable
ͭ͡publish()ͷฦΓ…
ConnectableObservable • connect() ϝιουΛ࣋ͭ • connect() ΛݺͿ͜ͱͰHotʹมྃ͢Δ • connect() ΛݺͿ·ͰObserver͕͍Α͏͕͍
·͍͕ಈ࡞͠ͳ͍
ConnectableObservable
ͳΜͰඞཁͳͷʁ • ྫ͑ɺෳͷobserver͕Hotม͞Εͨετ ϦʔϜͷΛ࠷ॳ͔ΒͪΌΜͱड͚औΓ͍ͨ ࣌ɻconnect()ΛݺͿ·Ͱಈ࡞͠ͳ͍ͷͰɺͦ ͷؒʹશͯͷobserverΛsubscribe͓ͤͯ͘͞ ͜ͱ͕Ͱ͖Δɻ
ͳΜͰඞཁͳͷʁ (ConnectableObservable͕ແ͍ͱͲ͏ͳΔ͔ߟ͑ͯΈ͍ͯͩ͘͞)
ConnectableObservableΛฦ͢Operator • multicast() • publish() • replay(bufferSize:) • replayAll()
multicast() • ͦͦHotมͱɺ෦తʹSubjectΛར ༻͍ͯ͠Δ͚ͩͰ͋Δɻ • multicast()SubjectΛࢦఆͯͦ͜͠ͰҰ୴Π ϕϯτΛड͚ΔΑ͏ʹ͢ΔOperator
multicast()
publish() • PublishSubjectʹmulticast͢Δ
• ReplaySubjectʹmulticast͢Δ replay(bufferSize:) / replayAll()
ConnectableObservable·ͱΊ • ColdͳObservableʹରͯ͠ɺmulticast() / publish() / replay(bufferSize:) / replayAll() Λݺͼ
ग़͢͜ͱͰ ConnectableObservableʹมͰ͖ Δɻ • ConnectableObservableʹରͯ͠connect()Λݺͼ ग़͢͜ͱͰHotͳObservableʹม͕ྃ͢Δɻ
࣍…
ConnectableObservable ཧղͨ͠
ଞͷHotؔ࿈ͷOperatorʁ
(෮श)Hotʹؔ࿈͢ΔΦϖϨʔλ Hotʹؔ࿈͢ΔΦϖϨʔλҎԼͷΈɻ ͜ΕΒ͕ಛʹݺΕͯͳ͚ΕHotʹม͞ΕΔ͜ͱͳ͍ɻ • multicast / publish • replay /
replayAll • connect / refCount • share / shareReplay • shareReplayLatestWhileConnected
ͱΓ͋͑ͣshare()Ͱ ͬͯΈΔ͔
share() ConnectableObservable͡Όͳͯ͘ ObservableͰฦ͖ͬͯͯΔ͠ ͖ͬͱHotΖʂʂʂ
Question2 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. ͳʹදࣔ͞Εͳ͍
ƅЧƅ)Űō?
Hotม ϙΠϯτͦͷ2 ۂऀ: RefCount
share()
refCount() • refCount() ConnectableObservableʹର͠ ͯݺΔ͏ҰͭͷOperatorͰ͋Δɻ
refCount() • Hotͷ֓೦Λ෴͢ΊΜͲ͍͘͞ศརͳͭ • Hotͷੑ࣭ͱͯ͠ʮsubscribe͠ͳͯ͘ಈ࡞ ͢Δʯͱ͍͏ͷ͕͋Δ͕ɺrefCount͕ڬ·Δ ͱʮHot͕ͩɺ࠷ॳʹsubscribe͞ΕΔ·Ͱಈ ࡞͠ͳ͍ʯΈ͍ͨͳڍಈʹͳΔɻ
refCount() • ࡞Γ୯७Ͱɺ࠷ॳʹsubscribe͞Εͨ࣌Ͱ ෦తʹconnect()ΛݺͿɻ
Question3 ͳΜͱදࣔ͞ΕΔͰ͠ΐ͏ʁ
None
Answer ਖ਼ղ…
A. 1,2,3
ͪΌΜͱHotม͞Εͯͨ (ͳΜͰʁʂͱࢥͬͨํલճͷεϥΠυΈͯΈ·͠ΐ͏)
ΓͷOperator
shareReplay(bufferSize:) • ໊લͷ௨Γɺshare + replay • share = publish +
refCount • shareReplay = publish + refCount + replay • ʮHot͕ͩɺ࠷ॳʹsubscribe͞ΕΔ·Ͱಈ࡞͠ͳ ͍ʯΛकΓͭͭࢦఆ͞Εͨݸ͚ͩΛreplay͢ Δ
shareReplay(bufferSize:) • ࣮ΊͬͪΌॏཁͰɺRxSwiftͷExampleͰΑ͘ʢʁʣ ΘΕ͍ͯΔɻ • มతʹѻ͍ͭͭɺ࠶ܭࢉͤ͞ͳ͍Α͏ʹ͢Δͱ͖ʹ shareReplay(1)Λ͚ͭΔͱΑ͍ (͜Εʹ͍ͭͯผ్ൃද͠ ·͢ɻ) •
RxSwift v2.5.0࣌ͰshareReplayʹ1Ҏ֎Λ͢ͱ࠶ܭࢉ ͕Δόάʁ༷ʁ͕͋Δɻshareಉ༷ͷݱ༗Γɻ
shareReplayLatestWhileConnected() • ໊લ͕ΊͬͪΌ͍ • ͜Μͳͷ͏ػձ͋Δͷʁͱࢥ͏͔͠Εͳ͍͕ɺ RxSwift(RxCocoa)Ͱఏڙ͞Ε͍ͯΔ DriverσϑΥϧτͰ͜Εͱಉ ͡ڍಈΛ͢ΔɻͳͷͰڍಈཧղ͓͖ͯ͘͠ɻ • ShareReplay1
ͱͷҧ͍ɺconnect தͰͳ͍ͱ࠷ޙͷ͕औΕͳ͍ ͜ͱɻͭ·Γ1 .Completed ͕ྲྀΕͨΒͦͷ͋ͱʹreplay͞Ε ͣɺ.Completed ͔͠ྲྀΕͯ͜ͳ͍ɻ • ڍಈͷৄࡉͳྫDriverͷͱ͖ʹઆ໌͢ΔͷͰ͜͜ͰׂѪɻ
Hotม·ͱΊ Hotʹม͢Δʹ • ConnectableObservableʹมޙɺconnect() ΛݺͿ • RefCountʹରͯ͠1ͭҎ্subscribeΛߦ͏
Ҏ্ʂʂ