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
180
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.5k
Marzipan の正体は何だったのか そして SwiftUI の衝撃/wwdc19_marzipan_swiftui
yusukehosonuma
2
910
標準パッケージにおけるテストでの利用例から学ぶ testing / quick パッケージ/golang-testing-quick
yusukehosonuma
4
12k
Swift で ParameterizedTest をやってみた話/swift-parameterized-test
yusukehosonuma
4
2.1k
Property-based test beginning with SwiftCheck
yusukehosonuma
1
5.8k
XCTest(再)入門/reintroduction-to-xctest
yusukehosonuma
0
500
ソースコードから読み解く - Quick はどのように実装されているのか?/quick-code-reading
yusukehosonuma
7
11k
Swift 4.2 はどのような進化をしているのか/whats-new-swift42
yusukehosonuma
16
15k
HTTPモックライブラリ「Mockingjay」を使ってみた話/swift-mockingjay
yusukehosonuma
5
3.9k
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
How to train your dragon (web standard)
notwaldorf
96
6.2k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
23
1.4k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
131
19k
Faster Mobile Websites
deanohume
309
31k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Building Better People: How to give real-time feedback that sticks.
wjessup
367
19k
Learning to Love Humans: Emotional Interface Design
aarron
273
40k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.8k
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!