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
110
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RxSwift 5min
http://kanmoba.connpass.com/event/25185/
USAMI Kosuke
January 27, 2016
More Decks by USAMI Kosuke
See All by USAMI Kosuke
Onsager代数とその周辺 / Onsager algebra tsudoi
usamik26
0
710
Apple HIG 正式名称クイズ結果発表 / HIG Quiz Result
usamik26
0
270
ゆめみ大技林製作委員会の立ち上げの話 / daigirin project
usamik26
0
400
@ViewLoadingプロパティラッパの紹介と自前で実装する方法 / @ViewLoading property wrapper implementation
usamik26
0
560
これからUICollectionViewを実践活用する人のためのガイド / Guide to UICollectionView
usamik26
1
830
Xcodeとの最近の付き合い方のはなし / Approach To Xcode
usamik26
2
740
UICollectionView Compositional Layout
usamik26
0
880
Coding Swift with Visual Studio Code and Docker
usamik26
0
590
Swift Extension for Visual Studio Code
usamik26
2
1.1k
Other Decks in Programming
See All in Programming
人間の目はかわらない、だからJPEGは30年もつ
yuzneri
12
18k
霧の中の代数的エフェクト
funnyycat
1
460
Go言語とトイモデルで学ぶTransformerの気持ち / fukuokago23-transformer
monochromegane
0
160
OpenSpecのproposalにbrainstormingを持たせてみた
tigertora7571
1
200
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.9k
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
970
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
140
AIが無かった頃の素敵な出会いの話
codmoninc
1
380
Built Our Own Background Agent at LayerX
layerx
PRO
9
4.9k
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
変わらないものが、変わるものを決める — 意図駆動開発 × イベントソーシング × イミュータブル | What Doesn't Change Decides What Can — IDD × Event Sourcing × Immutability
tomohisa
0
1.2k
壊れたパーサから始める関数型設計と構成的なパーサ #fp_matsuri
raiga0310
2
440
Featured
See All Featured
Designing for Performance
lara
611
70k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
30 Presentation Tips
portentint
PRO
1
360
Information Architects: The Missing Link in Design Systems
soysaucechin
0
1k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
610
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
620
Technical Leadership for Architectural Decision Making
baasie
3
460
Paper Plane
katiecoart
PRO
2
52k
Building AI with AI
inesmontani
PRO
1
1.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
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!