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
23k
Railsで実装されている機能のマイクロサービスへの切り離し / split to microservices from rails
mihyaeru21
1
740
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
250
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
620
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.5k
入門ReactiveX / about ReactiveX
mihyaeru21
3
420
RxSwiftでTwitterの ライブラリを作ってる話 / RxTwift
mihyaeru21
4
710
CrystalでTwitter botを作ってみた / Create a Twitter bot in Crystal
mihyaeru21
0
1.3k
Gotanda.pm #1
mihyaeru21
1
150
Other Decks in Technology
See All in Technology
WSUSが非推奨に!? Windowsの更新管理を改めて勉強する!
ebibibi
0
190
リスクから学ぶKubernetesコンテナセキュリティ/k8s-risk-and-security
mochizuki875
1
330
OPENLOGI Company Profile
hr01
0
54k
New Relicを活用したシステム監視の強化とオブザーバビリティ向上
sugoto911
1
110
Deno Deploy で Web Cache API を 使えるようになったので試した知見
toranoana
1
110
Product Utilization of Large Language Models Starting Today
ymatsuwitter
3
1.4k
tenntennはなんでnewmoにnew社したの? - YAPC::Hakodate 2024
tenntenn
PRO
0
290
kube-vipとkube-proxy置き換えCiliumを積んだ究極のK3sクラスタを建てる
logica0419
4
220
I tried the newly introduced certification "Applied Skills" on Microsoft Learn
mappie_kochi
0
230
Kubernetes Meetup Tokyo #67 - KEP-3619: Fine-grained SupplementalGroups Control / k8sjp67-kep-3619
everpeace
0
140
今こそ変化対応力を向上させるとき 〜ログラスが FAST に挑戦する理由〜 / Why Loglass is Talking on the Challenge of Agile Framework FAST
shioyang
0
110
DenoでもViteしたい!インポートパスのエイリアスを指定してラクラクアプリ開発
bengo4com
2
2k
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
Being A Developer After 40
akosma
84
590k
The Cult of Friendly URLs
andyhume
77
6k
Building a Scalable Design System with Sketch
lauravandoore
459
33k
Ruby is Unlike a Banana
tanoku
96
11k
The Invisible Side of Design
smashingmag
297
50k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
37
1.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
Git: the NoSQL Database
bkeepers
PRO
425
64k
Adopting Sorbet at Scale
ufuk
73
9k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
664
120k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
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 •
ͳͯ͘ࢮͳͳ͍͚Ͳ͋Δͱຯʹศར • ຯʹͬͯ͜