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
170
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
320
@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
770
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
LRパーサーはいいぞ
ydah
6
1.2k
M5UnitUnified 最新動向 2025/05
gob
0
130
In geheimer Mission: AI Agents entwickeln
joergneumann
0
110
エンジニア向けCursor勉強会 @ SmartHR
yukisnow1823
3
12k
Boost Your Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
830
Jakarta EE Meets AI
ivargrimstad
0
850
VitestのIn-Source Testingが便利
taro28
8
2.4k
エンジニアが挑む、限界までの越境
nealle
1
320
The Missing Link in Angular’s Signal Story: Resource API and httpResource
manfredsteyer
PRO
0
140
プロダクトエンジニアのしごと 〜 受託 × 高難度を乗り越えるOptium開発 〜
algoartis
0
190
開発者フレンドリーで顧客も満足?Platformの秘密
algoartis
0
200
Serving TUIs over SSH with Go
caarlos0
0
620
Featured
See All Featured
A Tale of Four Properties
chriscoyier
159
23k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.2k
BBQ
matthewcrist
88
9.6k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
47
2.7k
Speed Design
sergeychernyshev
29
930
4 Signs Your Business is Dying
shpigford
183
22k
Become a Pro
speakerdeck
PRO
28
5.3k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.2k
Build your cross-platform service in a week with App Engine
jlugia
230
18k
RailsConf 2023
tenderlove
30
1.1k
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 !