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と愉快な仲間たち / RxSwift with Units
Search
Mihyaeru
May 20, 2016
Technology
4
2.7k
RxSwiftと愉快な仲間たち / RxSwift with Units
Gotanda.mobile #1 on 2016/05/20
Mihyaeru
May 20, 2016
Tweet
Share
More Decks by Mihyaeru
See All by Mihyaeru
会計 freee バックエンドの今後 / freee backend api
mihyaeru21
8
24k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
760
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
640
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
入門ReactiveX / about ReactiveX
mihyaeru21
3
420
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
720
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
mihyaeru21
0
1.3k
Gotanda.pm #1
mihyaeru21
1
160
Other Decks in Technology
See All in Technology
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
Wantedly での Datadog 活用事例
bgpat
1
430
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
2
110
なぜCodeceptJSを選んだか
goataka
0
160
あの日俺達が夢見たサーバレスアーキテクチャ/the-serverless-architecture-we-dreamed-of
tomoki10
0
430
コンテナセキュリティのためのLandlock入門
nullpo_head
2
320
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
TSKaigi 2024 の登壇から広がったコミュニティ活動について
tsukuha
0
160
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
220
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
Postman と API セキュリティ / Postman and API Security
yokawasa
0
200
【re:Invent 2024 アプデ】 Prompt Routing の紹介
champ
0
140
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
The Cost Of JavaScript in 2023
addyosmani
45
7k
BBQ
matthewcrist
85
9.4k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
45
2.2k
Agile that works and the tools we love
rasmusluckow
328
21k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Visualization
eitanlees
146
15k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
1.2k
How to Ace a Technical Interview
jacobian
276
23k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
229
52k
Transcript
RxSwiftͱ༇շͳؒͨͪ Gotanda.mobile #1 in Mobile Factory on 2016/05/20 ϛώϟΤϧ@mihyaeru21
͓·͑୭Α • ϛώϟΤϧ @mihyaeru21 • ࠷ۙͷݴޠɿSwift/Kotlin/Perl • ·ͩ·ͩϋϯλʔ • ϞφυΛཧղ͍ͨ͠
RxSwit
Unit
Unit • Driver • Variable • ControlEvent/ControlProperty
Unit • RxCocoa͕ఏڙ͢Δศར͘Μ • ཧͱ͔ͷ୯Ґͱͯ͠ͷUnitʹ͔͚͍ͯΔΒ͍͠ ※RxCocoaʹؚ·ΕΔͱެࣜυΩϡϝϯτʹ͋Δ͚ͲVariableRxSwiftʹؚ·ΕΔ
Driver
Driver • Τϥʔ͕ྲྀΕͳ͍ • observe on ϝΠϯεϨου • share͞ΕΔ •
(ਖ਼֬ʹ shareReplayLatestWhileConnected )
Driver • ϞσϧͱUIͷؒʹೖͬͨΓ • UIͱUIΛܨ͍ͩΓ • ϋʔυΣΞͷυϥΠόιϑτΣΞతͳͱ͜Ζ͔Β ໊͚ΒΕͨ
Driver fetchUser() .map { $0.name } .observeOn(MainScheduler.instance) .bindTo(label.rx_text)
Driver fetchUser() .map { $0.name } .observeOn(MainScheduler.instance) .bindTo(label.rx_text) όοΫάϥϯυͰσʔλΛऔͬͯ͘Δ UIͷߋ৽ϝΠϯεϨουඞਢ
ϥϕϧͷςΩετʹόΠϯυ͢Δ
Driver fetchUser() .map { $0.name } .asDriver(onErrorJustReturn: "") .drive(label.rx_text)
Driver fetchUser() .map { $0.name } .asDriver(onErrorJustReturn: "") .drive(label.rx_text) Driverʹม
ϥϕϧͷςΩετʹόΠϯυ͢Δ
Driver let userName = fetchUser() .map { $0.name } .observeOn(MainScheduler.instance)
userName.bindTo(label.rx_text) userName.bindTo(otherLabel.rx_text)
Driver let userName = fetchUser() .map { $0.name } .observeOn(MainScheduler.instance)
.share() userName.bindTo(label.rx_text) userName.bindTo(otherLabel.rx_text) share()͠ͳ͍ͱ2ճൃՐ͢Δ
Driver let userName = fetchUser() .map { $0.name } .asDriver(onErrorJustReturn:
"") userName.drive(label.rx_text) userName.drive(otherLabel.rx_text)
Driver let userName = fetchUser() .map { $0.name } .asDriver(onErrorJustReturn:
"") userName.drive(label.rx_text) userName.drive(otherLabel.rx_text) share()తͳ͜ͱΛ͍ͯ͠Δ͔ΒൃՐ1ճͷΈ
Driver • ʮͦΕɺObservableͰͰ͖ͯΔ͡ΌΜʯ • ͍
Driver • UIͱܨ͙ҙਤΛ໌֬ʹ͢Δ • ҆શΛߴΊΔ • DriverʹมޙobserveεϨουͷมߋͰ͖ͳ͍ • share()ͯ͘͠ΕΔ
Variable
Variable • Τϥʔ͕ྲྀΕͳ͍ • share͞ΕΔ
Variable • BehaviorSubjectͷWrapper • valueϓϩύςΟΛ௨ͯ͠࠷৽ͷʹΞΫηεͰ͖Δ • valueϓϩύςΟͷೖon(.Next)ͱͯ͠ྲྀΕΔ • ObservableʹͳΔ͚ͲObserverʹͳΒͳ͍ •
Λྲྀͨ͢ΊʹvalueΛඞͣܦ༝͢Δ
Variable let variable = Variable(0) variable .asDriver() .map { "value:
\($0)" } .drive(label.rx_text) variable.value = 99 print("variable.value = \(variable.value)")
Variable let variable = Variable(0) variable .asDriver() .map { "value:
\($0)" } .drive(label.rx_text) variable.value = 99 print("variable.value = \(variable.value)") label.text͕”value: 99”ʹͳΔ VariableΤϥʔΛྲྀ͞ͳ͍͔Β Ҿແ͠൛ͷasDriver()͕͋Δ ಉظతʹΛऔಘͰ͖Δ
ControlEvent ControlProperty
ControlEvent/ControlProperty • Τϥʔ͕ྲྀΕͳ͍ • subscribe on ϝΠϯεϨου • observe on
ϝΠϯεϨου • share͞ΕΔ
ControlEvent/ControlProperty • UIύʔπͷΠϕϯτΛRxͱͭͳ͗ࠐΈ͘͢ • ControlEvent • Observable • ControlProperty •
Observable / Observer • Observer͋Δ
ControlEvent/ControlProperty textField.rx_text .asDriver() .drive(label.rx_text) ControlProperty Observer ControlPropertyΤϥʔΛྲྀ͞ͳ͍͔Β Ҿແ͠൛ͷasDriver()͕͋Δ
ControlEvent/ControlProperty textField.rx_text .bindTo(label.rx_text) ControlPropertyͷΠϕϯτϝΠϯεϨουͰྲྀΕΔ
ControlEvent/ControlProperty button.rx_tap .asDriver() .map { "tapped!" } .drive(textField.rx_text) ControlEventΤϥʔΛྲྀ͞ͳ͍͔Β Ҿແ͠൛ͷasDriver()͕͋Δ
ControlEvent ControlProperty
ControlEvent/ControlProperty • Cocoaͷ͍ΖΜͳͭʹ rx_* ͕ੜ͍͑ͯͯΖ͍Ζศར • https://github.com/ReactiveX/RxSwift/blob/master/ Documentation/API.md
ಥͳ·ͱΊ • ศརػೳͨͪ • Driver • Variable • ControlEvent/ControlProperty •
ͳͯ͘ࢮͳͳ͍͚Ͳ͋Δͱຯʹศར • ຯʹͬͯ͜