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
850
標準パッケージにおけるテストでの利用例から学ぶ 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
410
ソースコードから読み解く - 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
Building Adaptive Systems
keathley
38
2.3k
Thoughts on Productivity
jonyablonski
67
4.4k
Visualization
eitanlees
146
15k
Designing for humans not robots
tammielis
250
25k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
170
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Why Our Code Smells
bkeepers
PRO
335
57k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
29
2k
How GitHub (no longer) Works
holman
311
140k
Site-Speed That Sticks
csswizardry
2
190
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
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!