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
740
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.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
Oracle Cloud Infrastructureデータベース・クラウド:各バージョンのサポート期間
oracle4engineer
PRO
27
12k
よくわからんサービスについての問い合わせが来たときの強い味方 Amazon Q について
kazzpapa3
0
220
物価高なラスベガスでの過ごし方
zakky
0
380
20241031_AWS_生成AIハッカソン_GenMuck
tsumita
0
110
使えそうで使われないCloudHSM
maikamibayashi
0
170
チームを主語にしてみる / Making "Team" the Subject
ar_tama
4
310
AWS CDKでデータリストアの運用、どのように設計する?~Aurora・EFSの実践事例を紹介~/aws-cdk-data-restore-aurora-efs
mhrtech
4
650
ネット広告に未来はあるか?「3rd Party Cookie廃止とPrivacy Sandboxの効果検証の裏側」 / third-party-cookie-privacy
cyberagentdevelopers
PRO
1
130
Shift-from-React-to-Vue
calm1205
3
1.3k
IaC運用を楽にするためにCDK Pipelinesを導入したけど、思い通りにいかなかった話
smt7174
1
110
AWS CodePipelineでコンテナアプリをデプロイした際に、古いイメージを自動で削除する
smt7174
1
100
pandasはPolarsに性能面で追いつき追い越せるのか
vaaaaanquish
4
4.6k
Featured
See All Featured
The MySQL Ecosystem @ GitHub 2015
samlambert
250
12k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Documentation Writing (for coders)
carmenintech
65
4.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
246
1.3M
The Invisible Side of Design
smashingmag
297
50k
Docker and Python
trallard
40
3.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.2k
Imperfection Machines: The Place of Print at Facebook
scottboms
264
13k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
What's in a price? How to price your products and services
michaelherold
243
12k
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 •
ͳͯ͘ࢮͳͳ͍͚Ͳ͋Δͱຯʹศར • ຯʹͬͯ͜