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 reintroduction
Search
USAMI Kosuke
June 29, 2018
Programming
0
850
RxSwift reintroduction
Mobile Act OSAKA #5
https://mobileact.connpass.com/event/86668/
USAMI Kosuke
June 29, 2018
Tweet
Share
More Decks by USAMI Kosuke
See All by USAMI Kosuke
Onsager代数とその周辺 / Onsager algebra tsudoi
usamik26
0
610
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
160
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
310
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
470
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
730
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
660
UICollectionView Compositional Layout
usamik26
0
760
Coding Swift with Visual Studio Code and Docker
usamik26
0
500
Swift Extension for Visual Studio Code
usamik26
2
1k
Other Decks in Programming
See All in Programming
Thank you <💅>, What's the Next?
ahoxa
1
140
Optimizing JRuby 10
headius
0
320
国漢文混用体からHolloまで
minhee
1
190
ミリしらMCP勉強会
watany
4
760
SEAL - Dive into the sea of search engines - Symfony Live Berlin 2025
alexanderschranz
1
140
Building Scalable Mobile Projects: Fast Builds, High Reusability and Clear Ownership
cyrilmottier
2
290
AI Agents with JavaScript
slobodan
0
230
Ruby's Line Breaks
yui_knk
2
1k
Lambda(Python)の リファクタリングが好きなんです
komakichi
3
200
Agentic Applications with Symfony
el_stoffel
2
300
AIコーディングエージェントを 「使いこなす」ための実践知と現在地 in ログラス / How to Use AI Coding Agent in Loglass
rkaga
0
110
ウォンテッドリーの「ココロオドル」モバイル開発 / Wantedly's "kokoro odoru" mobile development
kubode
1
140
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
54
5.4k
A Modern Web Designer's Workflow
chriscoyier
693
190k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.2k
The World Runs on Bad Software
bkeepers
PRO
67
11k
Navigating Team Friction
lara
184
15k
Adopting Sorbet at Scale
ufuk
76
9.3k
Scaling GitHub
holman
459
140k
Fontdeck: Realign not Redesign
paulrobertlloyd
83
5.5k
GitHub's CSS Performance
jonrohan
1030
460k
How to Think Like a Performance Engineer
csswizardry
23
1.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
19
1.1k
Building Flexible Design Systems
yeseniaperezcruz
329
38k
Transcript
RxSwift ࠶ೖ USAMI Kosuke Fenrir Inc.
RxSwift ͱ
RxSwift ͱ • ඇಉظͷΠϕϯτΛड͚औΔͨΊͷΈ • UI Πϕϯτड͚औΓ • Web API
Ϩεϙϯεड͚औΓ • σʔλͷมԽͷࢹ
ίʔυྫ : UIButton button.rx.tap .subscribe { [unowned self] _ in
// Ϙλϯλοϓ࣌ͷॲཧ } .disposed(by: disposeBag)
ίʔυྫ : UITextField textField.rx.text .subscribe { [unowned self] _ in
// ςΩετೖྗ࣌ͷॲཧ } .disposed(by: disposeBag)
ίʔυྫ : Notification NotificationCenter.default.rx.notification(..) .subscribe { [unowned self] _ in
// ௨ड͚औΓ࣌ͷॲཧ } .disposed(by: disposeBag)
ίʔυྫ : URLSession session.rx.response(request) .catchError { // Τϥʔ࣌ͷॲཧ .subscribe {
// Ϩεϙϯεड͚औΓ࣌ͷॲཧ } .disposed(by: disposeBag)
ΠϕϯτॲཧͷྲྀΕ • Observable ʹ Πϕϯτ͕ྲྀΕͯ͘Δ Sequence • rx.tap, rx.text, rx.notification,
rx.response • Observable Λ subscribe ͢ΔͱΠϕϯτΛड͚औΕΔ • dispose ʹ subscription ͷഁغ
ิɿObservable ʹྲྀΕͯ͘Δͷ • ྲྀΕͯ͘ΔΠϕϯτ enum Ͱఆٛ͞Ε͍ͯΔ • .next :
• .error : Τϥʔऴྃ • .completed : ਖ਼ৗऴྃ
σʔλόΠϯσΟϯά
σʔλόΠϯσΟϯά • ྫ͑ɾɾɾ • ϞσϧͷͷมԽΛ UI ʹ͍͑ͨ • UI ͷͷมԽΛϞσϧʹ͍͑ͨ
• ͦͷͨΊͷखஈͱͯ͠ RxSwift ͕͑Δ
σʔλόΠϯσΟϯάͷͨΊͷखஈ • BehaviorRelay / PublishRelay • Observable ͷҰछ • .next
͚͕ͩྲྀΕΔɺऴྃ͠ͳ͍
Relay ͷ͍ํ : accept • accept Ͱ Relay ʹ .next
ΠϕϯτΛૹΔ͜ͱ͕Ͱ͖Δ let relay = BehaviorRelay<String>(value: "000") relay.accept("111") relay.accept("222")
Relay ͷ͍ํ : bind • subscribe ͷΘΓʹ bind ͕͑Δ relay
.bind(to: label.rx.text) textField.rx.text .bind(to: relay)
BehaviorRelay / PublishRelay • ྆ऀͷҧ͍ • ॳظΛ࣋ͭ / ࣋ͨͳ͍ •
value ϓϩύςΟͰݱࡏ͕औಘͰ͖Δ / Ͱ͖ͳ͍ • subscribe ͨ͠ͱ͖ݱࡏ͕ྲྀΕΔ / ྲྀΕͳ͍
ViewModel struct ViewModel { let username = BehaviorRelay<String>(value: "") }
ϞσϧͷͷมԽΛ͑Δ class ViewController { override func viewDidLoad() { viewModel.username .bind(to:
label.rx.text) .disposed(by: disposeBag) } }
UI ͷͷมԽΛ͑Δ class ViewController { override func viewDidLoad() { textField.rx.text.orEmpty
.bind(to: viewModel.username) .disposed(by: disposeBag) } }
όΠϯσΟϯάͷ͖
όΠϯσΟϯά୯ํ • ʮόΠϯσΟϯάʯͱ͍͏ͱํͬΆ͍͚Ͳɾɾɾ • RxSwift ͷ߹୯ํ • bind ࣮ subscribe
Ͱ͋Δ͜ͱΛΔͱ͔Γ͢ ͍
ํόΠϯσΟϯάผʹ͍Βͳ͍ • ํͩͱσʔλͷྲྀΕͷ In / Out ͕۠ผͮ͠Β͍ • ΞϓϦઃܭͱͯ͠ɺσʔλͷྲྀΕΔํΛҙࣝͰ͖Δ͜ͱେ ࣄ
RxSwift Λ͏͏͑Ͱ ͷཹҙ
ͳΜͰͰ͖͗͢Δ • ڧྗͳπʔϧͷͨΊແઅૢʹ͏ͱ͜Μ͕Β͕Δ͜ͱ͋Δ • ΞϓϦઃܭΛߟ͓͑ͯ͘ • RxSwift ͕Կ͔ͷΞϓϦઃܭΛ༩͑ͯ͘ΕΔΘ͚Ͱͳ͍ • ΞϓϦઃܭʹରͯ͠ɺ࣮Λָʹ͢Δπʔϧ
ϥΠϒϥϦࣗମͷن͕େ͖͍ • ༷ʑͳΫϥε͕͋ͬͯѲͮ͠Β͍ • খ͞ͳΛղܾ͍͚ͨͩ͠ͳΒಋೖΛͨΊΒ͏߹
্खʹ͖߹͑ศར • ͍Ͳ͜ΖΛͪΌΜͱߟ͑ͯ͑ɺͱͯศར • Enjoy RxSwift !