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
rxswift2.pdf
Search
Yusuke Hosonuma
June 13, 2016
0
170
rxswift2.pdf
Yusuke Hosonuma
June 13, 2016
Tweet
Share
More Decks by Yusuke Hosonuma
See All by Yusuke Hosonuma
KotlinTest で始める Property-based Testing/kotlintest-property-based-testing
yusukehosonuma
2
1.4k
Marzipan の正体は何だったのか そして SwiftUI の衝撃/wwdc19_marzipan_swiftui
yusukehosonuma
2
840
標準パッケージにおけるテストでの利用例から学ぶ testing / quick パッケージ/golang-testing-quick
yusukehosonuma
4
11k
Swift で ParameterizedTest をやってみた話/swift-parameterized-test
yusukehosonuma
4
2k
Property-based test beginning with SwiftCheck
yusukehosonuma
1
5.4k
XCTest(再)入門/reintroduction-to-xctest
yusukehosonuma
0
400
ソースコードから読み解く - Quick はどのように実装されているのか?/quick-code-reading
yusukehosonuma
7
11k
Swift 4.2 はどのような進化をしているのか/whats-new-swift42
yusukehosonuma
16
14k
HTTPモックライブラリ「Mockingjay」を使ってみた話/swift-mockingjay
yusukehosonuma
5
3.7k
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Rails Girls Zürich Keynote
gr2m
94
13k
Scaling GitHub
holman
458
140k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Statistics for Hackers
jakevdp
796
220k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
The Language of Interfaces
destraynor
154
24k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Done Done
chrislema
181
16k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Transcript
RxSwiftษڧձ ͦͷ1
ࣗݾհ • Yusuke Hosonuma • ʢ࠷ۙͷʣҰݴɿ ʢ։ൃऀʹʣΊ͙Γ⁊͍ʢίʔυΛʣ͗ • ࠷ۙɺݞ͜Γͱ͔ࠅ͍ͷͰϤΨΛ࢝Ί·ͨ͠ɻ
લճͷJOJORxSwift
લճ • ϦΞΫςΟϒϓϩάϥϛϯάʹֶ͍ͭͯΜͩ • ඇಉظετϦʔϜΛѻ͏ϓϩάϥϛϯά • ݴ͍͑ΔͱԿ͔͕ྲྀΕͯ͘ΔʮʯͰ͋Δ • ෦తʹObserverύλʔϯ͕ΘΕ͍ͯΔ
ิ • ϦΞΫςΟϒͱʮԠੑʯͱ͍͏ҙຯ • Կ͔ʹ࿈ಈͯ͠উखʹԿ͔͕มΘΔΠϝʔδ • ExcelͷࣜγεςϜϦΞΫςΟϒͳΞϓϦ έʔγϣϯͱݴ͑Δ
ࠓճ
நతͳ֓೦ΛΕͯ
࣮ફతͳRxSwift ʹ͍ͭͯ
ֶΜͰ͍͖·͢ʂ ʢલճͷ༰ΕͯOKʣ
ΞδΣϯμ • RxSwiftͷϞδϡʔϧ • RxSwiftͷΠϯετʔϧ • Observable<T> —> Observer<T> ͷଓ
• RxSwiftͷαϯϓϧίʔυ • ϥΠϒίʔσΟϯάʢؤுͬͯΈΔΑʂʣ
RxSwiftͷϞδϡʔϧ
RxSwiftͷϞδϡʔϧ • 2ͭͷϞδϡʔϧͰΓཱ͍ͬͯΔ • 1) RxSwift • 2) RxCocoa
1) RxSwift
1) RxSwift • import RxSwift • RxʢReactive ExtensionʣͷίΞ෦ͷػೳΛఏ ڙ͢ΔϞδϡʔϧ •
UIKitͳͲʹґଘ͠ͳ͍७ਮͳϦΞΫςΟϒϓϩ άϥϛϯάͷࡐྉΛఏڙ͢Δ • ଞͷϓϩάϥϛϯάݴޠͰຆͲಉ͡ʢͣʣ
2) RxCocoa ࢲͷ͜ͱݺΜͩʁ
2) RxCocoa • import RxCocoa • UIKitͳͲiOSʹґଘͨ͠෦ͷػೳΛఏڙ • UIViewNSNotificationʹରͯ͠ɺrx_xxxͱ͍ͬ ͨϓϩύςΟ͕Ճ͞ΕΔɻ
• ྫʣrx_tapɺrx_textɺrx_valueɺetc…
RxSwiftͷΠϯετʔϧ
RxSwiftͷΠϯετʔϧ • CocoaPodsͰ • CarthagoͰ • ͨͿΜকདྷతʹSwiftඪ४ͷύοέʔδϚωʔ δϟͰ • ·͊ৄ͘͠ެࣜυΩϡϝϯτΛಡΜͰͶʂ
Observable<T>ͱ Observer<T>ͷଓ
Observerύλʔϯͷ෮श • GoFͷ23ͷσβΠϯύλʔϯͷ1ͭ • iOSͰNSNotification͕ͦͷྫ • Observableʢ؍ଌ͞ΕΔͷʣͱɺ • Observerʢ؍ଌ͢Δͷʣ͕ొ͠ɺ •
Observableͷมߋ͕Observerʹ௨͞ΕΔ
RxSwiftͰͷ • ετϦʔϜ͕Observableʢ؍ଌ͞ΕΔͷʣ • ߪಡ͢Δͷ͕Observerʢ؍ଌ͢Δͷʣ • ্هʮʯͱʮ͓͋ͪΌΜʯʹஔ͖͑ͯ OKʢ౧ଠϝλϑΝʔ࠶ͼʣ
ॏཁͳίϯηϓτ
Observable<T>ͱ
Observer<T>
ଓʢbindʣ͢Δ͜ͱ͕ ՄೳͰ͋Δ
ͱΓ͋͑ͣίʔυྫ
ྫʣλοϓ࣌ʹϥϕϧߋ৽
͜Ε͕Rxʹ͓͚Δ σʔλόΠϯσΟϯά
σʔλόΠϯσΟϯά • Observable<T>ʢ؍͞ΕΔͷʣͱɺ • Observer<T>ʢ؍͢Δͷʣɺ • ଓʢbindʣՄೳͰ͋Δɻ • Tͷҙຯ͢Δͱ͜Ζܕɻ •
ͭ·Γಉ͡ܕͰͳ͚ΕଓͰ͖ͳ͍ɻ ʢTʹஔ͖͑ͯOKʣ
͏ҰίʔυΛݟͯΈΔ • 2.ͰจࣈྻܕͷετϦʔϜʢObservable<String>ʣʹม ͢Δ͜ͱͰɺ • UILabelͷrx_textଐੑʢObserver<String>ʣʹଓ͍ͯ͠ Δɻ • ͜ΕʹΑΓϘλϯλοϓͷετϦʔϜʹྲྀΕͨσʔλ͕ ࣗಈతʹUILabelͷtextଐੑʹө͞ΕΔɻ
RxSwift ίʔυαϯϓϧ
1. Ϙλϯͷλοϓ
Ϙλϯͷλοϓ • DisposeBagͱ͍͏ͷϝϞϦཧ༻ • ଞͷํ๏͋Δ͚Ͳɺ࠷ޙʹॻ͍͓͚ͯͱΓ͋͑ ͣOKͱࢥͬͯେৎ
2. εϥΠμʔ
εϥΠμʔ
3. NSNotification
NSNotification
ࡉ͔͍ҧ͍ ͋Δ͚ΕͲ
ຊ࣭తͳߟ͑ํ ڞ௨͍ͯ͠Δ
͢ͳΘͪ • Observable<T>ʢετϦʔϜʣΛ࡞Γग़͠ɺ • ετϦʔϜΛՃʢmapɺstartWithʣ͠ɺ • Observer<T>ʢ؍ଌऀʣʹଓ͢Δɻ
͜Ε͕Rxʹ͓͚Δ σʔλόΠϯσΟϯά RxετʔΧʔߦҝΛॿ͢ΔͷͰ அͯ͋͡Γ·ͤΜʢIt’s a jokeʣ
લճͷ෮श݉Ͷͯ • ετϦʔϜ҆ՁͰ؆୯ʹ࡞ΕΔ • ετϦʔϜΛՃ͢ΔͨΊͷखஈ͕ἧ͍ͬͯΔ • ετϦʔϜʢObservableʣɺ ؍ଌऀʢObserverʣʹଓ͢Δ͜ͱ͕ग़དྷΔ • ͯ͢ετϦʔϜͰ͋Δ
ϥΠϒίʔσΟϯά
όϦσʔγϣϯΛॻ͍ͯ ΈΔΑʂʢ࣌ؒ͋Εʣ
ࠓͷ·ͱΊ • RxSwiftͷϞδϡʔϧ • ίΞ෦ͷʮRxSwiftʯͱ • UIKit෦ͷʮRxCocoaʯ͕͋Δ • RxSwiftͷΠϯετʔϧ •
CocoaPods·ͨCarthagoͰͲ͏ͧ
ࠓͷ·ͱΊ • Observable<T> —> Observer<T> ͷଓ • Rxʹ͓͚ΔσʔλόΠϯσΟϯάػߏ • TܕΛද͠ɺಉ͡ܕͳΒଓͰ͖Δ
• ܕ͕ҟͳΔ߹ετϦʔϜΛՃʢmapͨ͠ Γʣ͢Δ͜ͱͰɺಉ͡ܕͷετϦʔϜʹ͢Δ͜ ͱग़དྷΔ
ࠓͷ·ͱΊ • RxSwiftͷαϯϓϧίʔυ • Ϙλϯλοϓ • εϥΠμʔ • NSNotification •
ͲΕڞ௨ͨ͠ύλʔϯɺObservable<T>ͱ Observer<T>ͷଓɺؒʹՃ͕͋ͬͨɻ
࠷ޙʹ
ࠓճͷεϥΠυͷ༰ Λཧղ͢Ε
RxSwiftͷίʔυ͔ͳΓಡ ΊΔΑ͏ʹͳΔͱࢥ͍·͢
ެࣜυΩϡϝϯτΛ ಡΜͰΈ·͠ΐ͏ʂ
Thanks!