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
890
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
680
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
230
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
370
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
530
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
790
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
710
UICollectionView Compositional Layout
usamik26
0
850
Coding Swift with Visual Studio Code and Docker
usamik26
0
550
Swift Extension for Visual Studio Code
usamik26
2
1.1k
Other Decks in Programming
See All in Programming
20260313 - Grafana & Friends Taipei #1 - Kubernetes v1.36 的開發雜記:那些困在 Alpha 加護病房太久的 Metrics
tico88612
0
170
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
130
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
120
DSPy入門 Pythonで実現する自動プロンプト最適化 〜人手によるプロンプト調整からの卒業〜
seaturt1e
1
690
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
290
モックわからないマン卒業記 ~振る舞いを起点に見直した、フロントエンドテストにおけるモックの使いどころ~
tasukuwatanabe
2
110
どんと来い、データベース信頼性エンジニアリング / Introduction to DBRE
nnaka2992
1
280
How to stabilize UI tests using XCTest
akkeylab
0
120
Swift ConcurrencyでよりSwiftyに
yuukiw00w
0
260
Docコメントで始める簡単ガードレール
keisukeikeda
1
110
ポーリング処理廃止によるイベント駆動アーキテクチャへの移行
seitarof
3
1k
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
250
Featured
See All Featured
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Done Done
chrislema
186
16k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
79
Chasing Engaging Ingredients in Design
codingconduct
0
140
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
100
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Six Lessons from altMBA
skipperchong
29
4.2k
The Curse of the Amulet
leimatthew05
1
9.9k
Designing Experiences People Love
moore
143
24k
Scaling GitHub
holman
464
140k
Balancing Empowerment & Direction
lara
5
940
Making the Leap to Tech Lead
cromwellryan
135
9.8k
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 !