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
160
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
390
ソースコードから読み解く - 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
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
41
2.1k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
KATA
mclloyd
29
13k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
GraphQLとの向き合い方2022年版
quramy
43
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Scaling GitHub
holman
458
140k
Code Reviewing Like a Champion
maltzj
519
39k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
364
22k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
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!