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
870
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
650
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
200
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
340
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
500
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
770
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
690
UICollectionView Compositional Layout
usamik26
0
810
Coding Swift with Visual Studio Code and Docker
usamik26
0
530
Swift Extension for Visual Studio Code
usamik26
2
1.1k
Other Decks in Programming
See All in Programming
Google Opalで使える37のライブラリ
mickey_kubo
3
150
What Spring Developers Should Know About Jakarta EE
ivargrimstad
0
530
Migration to Signals, Resource API, and NgRx Signal Store
manfredsteyer
PRO
0
130
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
120
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
530
CSC305 Lecture 12
javiergs
PRO
0
240
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
190
iOSでSVG画像を扱う
kishikawakatsumi
0
170
CSC305 Lecture 10
javiergs
PRO
0
290
Leading Effective Engineering Teams in the AI Era
addyosmani
7
650
Cursorハンズオン実践!
eltociear
2
1.2k
Android16 Migration Stories ~Building a Pattern for Android OS upgrades~
reoandroider
0
140
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
2.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.5k
Done Done
chrislema
185
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Building Applications with DynamoDB
mza
96
6.7k
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
Scaling GitHub
holman
463
140k
Why Our Code Smells
bkeepers
PRO
340
57k
Docker and Python
trallard
46
3.6k
Code Reviewing Like a Champion
maltzj
526
40k
We Have a Design System, Now What?
morganepeng
53
7.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 !