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
750
WebエンジニアのためのMySQLデータ構造基礎(再) / mysql data structure for web developer 2
mihyaeru21
0
260
WebエンジニアのためのMySQLデータ構造基礎 / mysql data structure for web developer
mihyaeru21
1
630
WebエンジニアのためのMySQL入門 / learning mysql for web developer
mihyaeru21
7
2.6k
入門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
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
CDCL による厳密解法を採用した MILP ソルバー
imai448
3
140
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
[CV勉強会@関東 ECCV2024 読み会] オンラインマッピング x トラッキング MapTracker: Tracking with Strided Memory Fusion for Consistent Vector HD Mapping (Chen+, ECCV24)
abemii
0
230
Amazon CloudWatch Network Monitor のススメ
yuki_ink
1
210
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
0
100
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
Platform Engineering for Software Developers and Architects
syntasso
1
520
Lambdaと地方とコミュニティ
miu_crescent
2
370
New Relicを活用したSREの最初のステップ / NRUG OKINAWA VOL.3
isaoshimizu
3
630
ドメインの本質を掴む / Get the essence of the domain
sinsoku
2
160
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
120
Featured
See All Featured
Bash Introduction
62gerente
608
210k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
The Pragmatic Product Professional
lauravandoore
31
6.3k
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
10 Git Anti Patterns You Should be Aware of
lemiorhan
655
59k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
25
1.8k
Code Review Best Practice
trishagee
64
17k
Visualization
eitanlees
145
15k
Stop Working from a Prison Cell
hatefulcrawdad
267
20k
Statistics for Hackers
jakevdp
796
220k
It's Worth the Effort
3n
183
27k
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 •
ͳͯ͘ࢮͳͳ͍͚Ͳ͋Δͱຯʹศར • ຯʹͬͯ͜