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
100
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
640
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
180
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
330
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
480
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
750
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
670
UICollectionView Compositional Layout
usamik26
0
790
Coding Swift with Visual Studio Code and Docker
usamik26
0
510
Swift Extension for Visual Studio Code
usamik26
2
1k
Other Decks in Programming
See All in Programming
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
170
テスト駆動Kaggle
isax1015
1
620
DMMを支える決済基盤の技術的負債にどう立ち向かうか / Addressing Technical Debt in Payment Infrastructure
yoshiyoshifujii
3
410
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
180
効率的な開発手段として VRTを活用する
ishkawa
0
160
イベントストーミング図からコードへの変換手順 / Procedure for Converting Event Storming Diagrams to Code
nrslib
2
1.1k
状態遷移図を書こう / Sequence Chart vs State Diagram
orgachem
PRO
2
210
生成AI時代のコンポーネントライブラリの作り方
touyou
1
290
テストから始めるAgentic Coding 〜Claude Codeと共に行うTDD〜 / Agentic Coding starts with testing
rkaga
15
5.6k
#QiitaBash MCPのセキュリティ
ryosukedtomita
1
1.5k
NPOでのDevinの活用
codeforeveryone
0
900
Advanced Micro Frontends: Multi Version/ Framework Scenarios @WAD 2025, Berlin
manfredsteyer
PRO
0
390
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
51
8.6k
RailsConf 2023
tenderlove
30
1.1k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
138
34k
Designing for humans not robots
tammielis
253
25k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
The Pragmatic Product Professional
lauravandoore
35
6.7k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
Building Adaptive Systems
keathley
43
2.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
130
19k
The Straight Up "How To Draw Better" Workshop
denniskardys
235
140k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.9k
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!