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
600
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
160
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
310
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
460
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
720
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
650
UICollectionView Compositional Layout
usamik26
0
750
Coding Swift with Visual Studio Code and Docker
usamik26
0
490
Swift Extension for Visual Studio Code
usamik26
2
1k
Other Decks in Programming
See All in Programming
Devinのメモリ活用の学びを自社サービスにどう組み込むか?
itarutomy
0
1.4k
SideKiqでジョブが二重起動した事象を深堀りしました
t_hatachi
0
180
snacks.nvim内のセットアップ不要なプラグインを紹介 / introduce_snacks_nvim
uhooi
0
310
NestJSのコードからOpenAPIを自動生成する際の最適解を探す
astatsuya
0
160
GDG Super.init(version=6) - From Where to Wear : 모바일 개발자가 워치에서 발견한 인사이트
haeti2
0
540
Going Structural with Named Tuples
bishabosha
0
150
DenoでOpenTelemetryに入門する
yotahada3
2
280
Devin , 正しい付き合い方と使い方 / Living and Working with Devin
yukinagae
1
500
Fluent UI Blazor 5 (alpha)の紹介
tomokusaba
0
120
MCP世界への招待: AIエンジニアが創る次世代エージェント連携の世界
gunta
2
450
‘무차별 LGTM~👍’만 외치던 우리가 ‘고봉밥 코드 리뷰’를?
hannah0731
0
510
読もう! Android build ドキュメント
andpad
1
210
Featured
See All Featured
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
120k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
7
610
Thoughts on Productivity
jonyablonski
69
4.5k
Java REST API Framework Comparison - PWX 2021
mraible
29
8.5k
For a Future-Friendly Web
brad_frost
176
9.6k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
Code Reviewing Like a Champion
maltzj
521
39k
A Tale of Four Properties
chriscoyier
158
23k
Building Your Own Lightsaber
phodgson
104
6.3k
Building Adaptive Systems
keathley
40
2.5k
The Language of Interfaces
destraynor
156
24k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.1k
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!