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
RxSwift 5min
Search
USAMI Kosuke
January 27, 2016
Programming
0
91
RxSwift 5min
http://kanmoba.connpass.com/event/25185/
USAMI Kosuke
January 27, 2016
Tweet
Share
More Decks by USAMI Kosuke
See All by USAMI Kosuke
Onsager代数とその周辺 / Onsager algebra tsudoi
usamik26
0
530
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
110
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
280
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
430
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
690
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
610
UICollectionView Compositional Layout
usamik26
0
680
Coding Swift with Visual Studio Code and Docker
usamik26
0
450
Swift Extension for Visual Studio Code
usamik26
2
910
Other Decks in Programming
See All in Programming
Arm移行タイムアタック
qnighy
0
330
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
みんなでプロポーザルを書いてみた
yuriko1211
0
280
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Quine, Polyglot, 良いコード
qnighy
4
650
as(型アサーション)を書く前にできること
marokanatani
10
2.7k
RubyLSPのマルチバイト文字対応
notfounds
0
120
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
광고 소재 심사 과정에 AI를 도입하여 광고 서비스 생산성 향상시키기
kakao
PRO
0
170
Featured
See All Featured
Facilitating Awesome Meetings
lara
50
6.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
A Tale of Four Properties
chriscoyier
156
23k
Typedesign – Prime Four
hannesfritz
40
2.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Unsuck your backbone
ammeep
668
57k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Designing Experiences People Love
moore
138
23k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Designing for humans not robots
tammielis
250
25k
Visualization
eitanlees
145
15k
Transcript
RxSwift USAMI Kosuke (Fenrir Inc.)
RxSwift ReactiveX for Swift → ReactiveX family : Rx.NET /
RxJS / RxJava / ...
RxSwift Released! 2.0.0 : 2016/01/02 (Latest release = 2.1.0 :
2016/01/11)
5ͰΘ͔Δ RxSwift
ͱΓ͋͑ͣ ͬͯΈΔͨΊ ͷࣝ
ͱΓ͋͑ͣͬͯΈΔͨΊͷࣝ → Observable → Subscribe → Error Handling
Observable
Observable → ඇಉظσʔλετϦʔϜ → UI ͔ΒͷΞΫγϣϯ → OS ͔Βͷ Notification
→ URL ηογϣϯͷϨεϙϯε
Observable ͷཁૉ → Next → Completed → Error
Next → case .Next(let value) → value = ετϦʔϜͷσʔλ
Completed → case .Completed → ετϦʔϜͷऴΘΓ → ໌ࣔతͳऴΘΓ͕ͳ͍ετϦʔϜ͋Δ
Error → case .Error(let error) → error = ErrorType ܕͷ
→ ετϦʔϜͷऴΘΓͰ͋Δ
Observable ͷੜ → Observable.create ͳͲͰੜ → RxCocoa ͕༻ҙ͍ͯ͠Δ rx_tap /
rx_notification / rx_response / ...
Subscribe
Subscribe → ετϦʔϜ͔ΒσʔλΛड͚औΔ → subscribeNext → subscribeCompleted → subscribeError
ྫ : UIButton ΞΫγϣϯ hogeButton.rx_tap .subscribeNext { [unowned self] _
in self.hoge() }
ྫ : NSNotification let center = NSNotificationCenter.defaultCenter() center.rx_notification(UIApplicationDidBecomeActiveNotification) .subscribeNext {
[unowned self] _ in self.hoge() }
ྫ : NSURLSession let session: NSURLSession = ... let request
= NSURLRequest(...) session.rx_response(request) .subscribeNext { (data, response) in ... }
Error Handling
catchError hogeObservable .catchError { error in ... } .subscribeNext {
... }
retry hogeObservable .retry(3) // 3ճ·ͰϦτϥΠ .subscribeNext { ... }
retryWhen hogeObservable .retryWhen { _ in // 30ඵޙʹϦτϥΠ return Observable.timer(30,
...) } .subscribeNext { ... }
͏ͪΐͬͱ Rx Β͘͠
͏ͪΐͬͱ Rx Β͘͠ → Transforming / Filtering → Combining →
Subject
Transforming / Filtering
Transforming / Filtering → Observable ʹରͯ͠ map / flatMap /
filter ͳͲ → Array ʹର͢Δ map / flatMap / filter ͱಉ༷
map hogeObservable .map { $0 * 10 }
flatMap
filter
Chaining Operators hogeObservable .filter { ... } .map { ...
} .subscribeNext { ... }
Combining
Combining → ෳͷετϦʔϜΛͻͱͭͷετϦʔϜʹ·ͱΊ Δ
merge
combineLatest
Subject
Subject → Observable ͷҰछ → ֎෦͔Β Subject ʹσʔλΛྲྀͤΔ → Hot
Observable
σʔλΛྲྀ͢ let subject = PublishSubject<String>() subject.on(.Next("a")) subject.on(.Next("b")) subject.on(.Completed) ////////// subject.subscribeNext
{ ... }
ετϦʔϜͷذ → ͻͱͭͷετϦʔϜ͔Βෳͷ Subscriber ʹ → ʢHot Observableʣ
͓͞Β͍
͓͞Β͍ → Observable → Subscribe → Error Handling → Transforming
/ Filtering → Combining → Subject
Have a Happy RxSwift Life!