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
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
Rails Girls Zürich Keynote
gr2m
93
13k
How to Ace a Technical Interview
jacobian
275
23k
Git: the NoSQL Database
bkeepers
PRO
425
64k
The World Runs on Bad Software
bkeepers
PRO
65
11k
GitHub's CSS Performance
jonrohan
1030
460k
RailsConf 2023
tenderlove
29
880
Documentation Writing (for coders)
carmenintech
65
4.4k
Large-scale JavaScript Application Architecture
addyosmani
510
110k
A Philosophy of Restraint
colly
203
16k
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!