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
91
アニメーション実践入門
kotaro
3
580
iOSアプリ開発にもDIツールを!
kotaro
5
1.2k
Swiftで気持ち良く開発したアプリを気持ち良くSubmitする
kotaro
0
7.2k
Other Decks in Programming
See All in Programming
CloudflareStack でRAGに入門
asahiiwm
0
140
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.5k
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
110
テストコード書いてみませんか?
onopon
2
270
php-conference-japan-2024
tasuku43
0
390
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
130
KMP와 kotlinx.rpc로 서버와 클라이언트 동기화
kwakeuijin
0
260
Beyond ORM
77web
11
1.5k
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
220
今年一番支援させていただいたのは認証系サービスでした
satoshi256kbyte
1
270
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
520
htmxって知っていますか?次世代のHTML
hiro_ghap1
0
370
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Designing for humans not robots
tammielis
250
25k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Testing 201, or: Great Expectations
jmmastey
41
7.2k
Building Adaptive Systems
keathley
38
2.3k
The Cult of Friendly URLs
andyhume
78
6.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
The Pragmatic Product Professional
lauravandoore
32
6.3k
For a Future-Friendly Web
brad_frost
176
9.5k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
3
320
Done Done
chrislema
182
16k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
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!