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
川で例えずに理解するObservable
Search
Yoshikuni Kato
February 14, 2017
Programming
3
2.4k
川で例えずに理解するObservable
Presented at 集まれSwift好き!Swift愛好会 vol16
https://love-swift.connpass.com/event/48820/
Yoshikuni Kato
February 14, 2017
Tweet
Share
More Decks by Yoshikuni Kato
See All by Yoshikuni Kato
The Elm Architecture & Swift
yoching
0
880
iOS developers community in Tokyo
yoching
0
640
Swiftエンジニアが海外のポジションに応募する
yoching
10
2.9k
App Architecture By Manual DI
yoching
0
640
Passing function to function arguments
yoching
0
610
「新規アプリの設計」を設計する
yoching
1
1.8k
App Architecture By Manual DI
yoching
2
520
関数を引数として渡す書き方のポイント
yoching
0
750
App Architecture Sample
yoching
0
92
Other Decks in Programming
See All in Programming
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
100
Remix on Hono on Cloudflare Workers
yusukebe
1
280
Jakarta Concurrencyによる並行処理プログラミングの始め方 (JJUG CCC 2024 Fall)
tnagao7
1
290
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
170
現場で役立つモデリング 超入門
masuda220
PRO
15
3.2k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
CSC509 Lecture 09
javiergs
PRO
0
140
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
Outline View in SwiftUI
1024jp
1
320
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
1
290
Featured
See All Featured
Speed Design
sergeychernyshev
24
610
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.8k
Code Review Best Practice
trishagee
64
17k
The Language of Interfaces
destraynor
154
24k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Adopting Sorbet at Scale
ufuk
73
9.1k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
4
370
A designer walks into a library…
pauljervisheath
203
24k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Transcript
Ͱྫ͑ͣʹཧղ͢ΔObservable @yoshikuni_kato Swi$Ѫձ vol16 2017/02/14! 1
Who am I? • Ճ౻༝܇ʢYoshikuni Katoʣ @yoshikuni_kato • iOSΤϯδχΞ •
Yahoo! Japan -> Φϋί • ʮϥδ͐ʯ͘Μ → • Interests: ઃܭ / FRP / Coordinator PaCern / UI࣮ • try! SwiFʢ&ϋοΧιϯʣߦ͖·͢ʂ 2
Agenda 1. ͡Ίʹɹ~ObservableͷΑ͋͘Δྫ͑~ 2. Ͱྫ͑ͣʹཧղ͢ΔObservable 3. Hot / ColdʢReac7veSwi;ͷεεϝʣ 3
͡Ίʹ 4
Func%onal Reac%ve Programming • ϓϩάϥϛϯάͷύϥμΠϜ • swi% libraries • Reac.veSwi%
(Reac.veCocoa) ɹɹ˞ Reac.veCocoa3͔Βswi%Խ͞Ε͍ͯ·͢ʢݱࡏɺ5ʣ ɹɹ˞ 5ͰϦϙδτϦ͕ཧ͞ΕɺຊମʢReac.veSwi%ʣͱUIKit֦ு ʢReac.veCocoaʣͱͳΓ·ͨ͠ • RxSwi% • RxͱݺͣʹFRPͱݺͼ͍ͨ 5
Observableͱ • Observable ɹ= Stream of values over 2me ɹ࣌ؒ࣠ʹԊͬͯൃੜ͢ΔͷετϦʔϜ
1 ! Observableͬͯɺʮ؍Ͱ͖Δʯͬͯ ͍͏ҙຯͩΑͳ͊ɾɾɾ ɹʮ࣌ؒʯʮετϦʔϜʯͱͲ͏͍͏ ؔͳΜͩΖ͏ʁ 1 The introduc.on to Reac.ve Programming you've been missing 6
Α͋͘Δྫ͑ • Observable = ! ͬͯʢιϑτΣΞతʹʣԿʁ ɹ ਫͲ͔͜ΒྲྀΕͯ͘Δͷʁ ɹ
ྲྀΕͨਫͲ͜ʹߦͬͯ͠·͏ͷʁ ɹ HotͱCold͕͋ΔΈ͍͚ͨͩͲɾɾɾɾ 7
ྫ͑Δ͜ͱͷޭࡑ ! - ͱ͖ͬͭͦ͢͏ʹࢥ͑Δ ! - ؒҧͬͨʢ࣮ͱҟͳΔʣཧղΛͯ͠͠·͏Մೳੑ͕͋Δ - தͷιʔεΛͲ͏ಡΜͰ͍͍͔͔Βͳ͍ ιϑτΣΞతͳߏΛཧղ͢Δ͜ͱॏཁ
8
Ͱྫ͑ͣʹཧղ͢ΔObservable 9
ऍ • FRPڞ௨ͷߟ͑ํʢͷͣʣ • Reac(veSwi-ϕʔε • RxSwi-ͷํιʔεΛ͖ͪΜͱಡΊͳ͔ͬͨͷͰɺؒҧͬͯ ͍ͨΒ͢Έ·ͤΜ! • ྫͱ্ͯ͛͠Δίʔυ͔ͳΓ؆ུԽͨ͠ͷ
10
Observerύλʔϯ͕جૅ 11
Observer = closure ʢΫϩʔδϟʔͷബ͍ϥούʔͱ࣮ͯ͠ʣ • ͲΜͳΫϩʔδϟʔ͔ʁ Event -> Void {
event: Event in // logics when changed } 12
Event // ReactiveSwift-1.0 ͷ߹ enum Event<Value, Error> { // RxSwiftͰErrorͷࢦఆͳ͠
case value(Value) // RxSwiftͷ߹next case failed(Error) // RxSwiftͷ߹ error(Swift.Error) case completed case interrupted // ReactiveSwiftͰͳ͠ } 13
Observable = Observerͷొઌ • Observable means "؍Ͱ͖Δͷ" • Observerͷcollec0onΛ͍࣋ͬͯΔ //
ΠϝʔδͰ͢ʂʂ class Observable { var observers: [Observer] } ※ ࣮ࡍʹɺλμͷྻͰͳ͘ɺͬͱෳࡶͳػߏͰ͢ 14
observe = ObserverΛొ͢Δ Observer(closure)ΛɺObservableͷObserver collec/onʹՃ͢Δ ※ Rxܥͩͱ"subscribe"ͱ͍͏໊લ 15
Observable = Stream of values over 1me ͱ ઌʹΫϩʔδϟʔ͕ొ͞Εͯ͋Δ ʹ
ʢObservableଆ͔ΒݟΕʣ ɹɹҙͷλΠϛϯάͰɺొ͞ΕͨΫϩʔδϟʔΛ࣮ߦͰ͖Δ → ࣌ؒʹԊͬͯൃੜ͢ΔΛදݱͰ͖Δ → มͦͷͷ͕ɺετϦʔϜʢΛநԽͨ͠ͷʣͱଊ͑ΒΕΔ ※ खଓ͖ܕతͳʮม͕ϝϞϦྖҬ(orΦϒδΣΫτ)Λ͍ࣔͯ͠Δʯ ͱ͍͏͜ͱΑΓந͕ߴ͍ 16
1 1 The introduc.on to Reac.ve Programming you've been missing
17
ʢ༨ஊʣ໋໊͕͔Γʹ͍͘ʁ ӳޠతɿObserver observe observable. (S-V-O) ίʔυɿobservable.observe(observer) ӳޠతͳҙຯͱ࣮ࡍͷڍಈ͕ର ʢຊདྷɺobservable.observed(by: observer)ɹͳͲʣ Reac%veSwi*Ͱଟগٞʹͳ͍ͬͯΔ
2 2 Rename Signal.observe(_:) 18
operator = observable -> observableͷม • map / filter /
flatMap / combineLatestͳͲͳͲɾɾɾ • RxMarble / RACMarbleΛࢀর 19
ʮҙͷλΠϛϯάͰ࣮ߦ͢ΔʯͷΈ Reac%veSwi*ͷ߹ • Signal(HotObservable)innerObserverͱηοτͰ࡞ΒΕɺinnerObserverSignalͷࢀরΛ࣋ͭ • innerObserverΛ࣮ߦ͢ΔʢobserverʹΠϕϯτΛ͢ʣ -> SignalͷobserversΛશͯʹΠϕϯτΛ͢ // Πϝʔδ
let innerObserver = { event in for observer in signal.observers { observer.send(event) } } • operator(map/filter/...)ɺ͜ͷinnerObserverΛɺલͷSignalͷobserverʹొ͢ΔΑ͏ͳܗ 20
Hot / Cold ʢReac%veSwi*ͷεεϝʣ 21
Hot / Cold • Hot / Coldʢ֓೦ʣ͔ΒೖΔͱ͔Γʹ͍͘ • Reac.veSwi3ͷߟ͑ํ͕ࢀߟʹͳΔ 22
Reac%veSwi*(Cocoa)ʹ͓͚Δ Hot/Cold • Reac&veCocoa2·ͰɿHot/Cold྆ํಉ͡ܕʢࠓͷRxͱಉ༷ʣ • Reac&veCocoa3Ҏ߱ɿHot/ColdΛܕͰ • Hot : Signal
• Cold: SignalProducer ͭ·ΓʮHotObservable ͱ ͦͷੜثʯͱཧղͰ͖Δ 23
Signal / SignalProducerʹ͍ͭͯ Qiitaʹ࠷ۙهࣄΛॻ͖·ͨ͠ Reac%veSwi* جຊཁૉͷ͍ํ Signal / SignalProducerฤ 24
Reac%veSwi* vs RxSwi* 25
Reac%veSwi* vs RxSwi* ! • Hot / Coldͷѻ͍͕͔Γ͍͢ • Τϥʔͷܕ͕ࢦఆͰ͖Δ
• ֮͑Δܕ͕গͳ͍ʢSignal/SignalProducer/Property/Ac7on/Disposable͘Β ͍ʣ • தͷ࣮ͷɺϑΝΠϧ͕গͳ͘ɺಡΈͦ͢͏ͳҹʢʹͳͬͨʣ • Carthageͷ࣮ʹ༻͞Ε͍ͯΔ 26
Reac%veSwi*ͷϑΝΠϧߏ 27
Reac%veSwi* vs RxSwi* ! • ຊޠͷυΩϡϝϯτ͕গͳ͍ • ݕࡧͯ͠ɺݹ͍هࣄ(Obj-C)͕ώοτ͕ͪ͠ • όʔδϣϯʹΑΔഁյతมߋ͕ଟ͍
• ίϛϡχςΟ͕ऑΊʢRealmͱͷ࿈ܞͳͲʣ • ΦϑΟγϟϧͷαϯϓϧͳͲ͕ͳ͍ 28
·ͱΊ 29
·ͱΊ • FRPΦϒβʔόʔύλʔϯ͕ࠜఈʹ͋Δ • ObservableͰΠϕϯτετϦʔϜͦͷͷΛදͤΔ • ιϑτΣΞతͳߏΛཧղ͢Δ͜ͱॏཁ • Reac.veSwi2ʢReac.veCocoaʣͬͯΈ͍ͯͩ͘͞! 30
iOSΤϯδχΞืूத • ࣄۀɿUX/UIσβΠϯ & ։ൃ ɹ ʢࠓͷͱ͜Ζʣ৽نडୗ։ൃϝΠϯ • ࣾһɿ20໊ڧʢiOSΤϯδχΞ 3໊ʣ
• ͪΖΜSwi/ • ։ൃͷࣗ༝ߴ͍ • try ! Swi/ (16/17) / iOSDC εϙϯαʔ • UI࣮͖ͳਓɺઃܭ͖ͳਓٻΉ 31
Thank you! 32
ิ 33
ࢲ͕Reac%veSwi*Λ͍࢝ΊͨܦҢ • ࠷ॳʢ2016/3݄͝ΖʣRxSwi-ΛʢྲྀߦΓͰʣษڧ • Reac1veSwi-Meetup@WantedlyͰReac1veCocoaͷΛฉ͖ɺ ઃܭ͕ྑͦ͞͏ͩͱࢥ͍ɺ͍࢝ΊΔ • @inamy͞Μɺ@ikesyo͞ΜɺNick͞Μ • ࠓޙչ͍ͯ͠ͳ͍
34
ࢀߟ • Reac&veCocoa/Reac&veSwi. • Reac&veCocoa/Reac&veCocoa • RACCommunity • Reac&veX/RxSwi. •
Reac&ve Swi. Meetup @WantedlyΛ։࠵͠·ͨ͠ʂ • @ikesyo͞Μͷࢿྉ • Reac&veSwi. جຊཁૉͷ͍ํ Signal / SignalProducerฤ 35