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
Goで作る、開発・CI環境
sin392
0
230
Porting a visionOS App to Android XR
akkeylab
0
460
Google Agent Development Kit でLINE Botを作ってみた
ymd65536
2
250
システム成長を止めない!本番無停止テーブル移行の全貌
sakawe_ee
1
200
猫と暮らす Google Nest Cam生活🐈 / WebRTC with Google Nest Cam
yutailang0119
0
120
Blazing Fast UI Development with Compose Hot Reload (droidcon New York 2025)
zsmb
1
290
Startups on Rails in Past, Present and Future–Irina Nazarova, RailsConf 2025
irinanazarova
0
110
すべてのコンテキストを、 ユーザー価値に変える
applism118
3
1.3k
Python型ヒント完全ガイド 初心者でも分かる、現代的で実践的な使い方
mickey_kubo
1
120
Rubyでやりたい駆動開発 / Ruby driven development
chobishiba
1
710
The Modern View Layer Rails Deserves: A Vision For 2025 And Beyond @ RailsConf 2025, Philadelphia, PA
marcoroth
1
150
脱Riverpod?fqueryで考える、TanStack Queryライクなアーキテクチャの可能性
ostk0069
0
140
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
A Tale of Four Properties
chriscoyier
160
23k
Become a Pro
speakerdeck
PRO
29
5.4k
We Have a Design System, Now What?
morganepeng
53
7.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.5k
Speed Design
sergeychernyshev
32
1k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Practical Orchestrator
shlominoach
189
11k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
161
15k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
126
53k
Code Review Best Practice
trishagee
69
18k
Bash Introduction
62gerente
613
210k
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!