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
830
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
530
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
110
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
280
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
430
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
690
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
610
UICollectionView Compositional Layout
usamik26
0
680
Coding Swift with Visual Studio Code and Docker
usamik26
0
450
Swift Extension for Visual Studio Code
usamik26
2
910
Other Decks in Programming
See All in Programming
イベント駆動で成長して委員会
happymana
1
320
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
340
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
300
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
430
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
3
690
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
140
Better Code Design in PHP
afilina
PRO
0
130
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Featured
See All Featured
Practical Orchestrator
shlominoach
186
10k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Typedesign – Prime Four
hannesfritz
40
2.4k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Site-Speed That Sticks
csswizardry
0
27
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
A Modern Web Designer's Workflow
chriscoyier
693
190k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
48k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.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 !