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
信頼性に挑む中で拡張できる・得られる1人のスキルセットとは?
ken5scal
2
530
Amplify Gen2 Deep Dive / バックエンドの型をいかにしてフロントエンドへ伝えるか #TSKaigi #TSKaigiKansai #AWSAmplifyJP
tacck
PRO
0
370
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
SREによる隣接領域への越境とその先の信頼性
shonansurvivors
2
520
Platform Engineering for Software Developers and Architects
syntasso
1
520
Python(PYNQ)がテーマのAMD主催のFPGAコンテストに参加してきた
iotengineer22
0
470
社内で最大の技術的負債のリファクタリングに取り組んだお話し
kidooonn
1
550
AWS Lambda のトラブルシュートをしていて思うこと
kazzpapa3
2
170
AIチャットボット開発への生成AI活用
ryomrt
0
170
Terraform CI/CD パイプラインにおける AWS CodeCommit の代替手段
hiyanger
1
240
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
Lexical Analysis
shigashiyama
1
150
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
250
21k
Site-Speed That Sticks
csswizardry
0
23
How to train your dragon (web standard)
notwaldorf
88
5.7k
Automating Front-end Workflow
addyosmani
1366
200k
Unsuck your backbone
ammeep
668
57k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
Code Review Best Practice
trishagee
64
17k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
Building an army of robots
kneath
302
43k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Designing the Hi-DPI Web
ddemaree
280
34k
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 •
ͳͯ͘ࢮͳͳ͍͚Ͳ͋Δͱຯʹศར • ຯʹͬͯ͜