SlideShare a Scribd company logo
RXSWIFT
REACTIVE PROGRAMMING WITH
+ =
ABOUT ME
ABOUT YOU
▸Swift
▸Reactive programming
TRADITIONAL VS. REACTIVE
A SIMPLE EXAMPLE IN IOS
MODEL
VIEW MODEL
VIEW CONTROLLER
Reactive Programming with RxSwift
REACTIVE VIEW MODEL
REACTIVE VIEW CONTROLLER
THE RESULTS
40% SAVINGS
Reactive Programming is essentially about
modeling asynchronous sequences
What is Reactive Programming?
Reactive Programming is essentially about
modeling asynchronous sequences
What is Reactive Programming?
Reactive Programming is essentially about
modeling asynchronous sequences
So what is RxSwift?
RxSwift implements patterns, types, and
operators to create and work with
Observable sequences
REACTIVE EXTENSIONS
N
ov.‘09
Rx.N
ET
RxJS
M
ar.‘10
RxJava
M
ar.‘12
RxC
pp
N
ov.‘12
RxRuby
D
ec.‘12
RxScala,RxC
lojure,RxG
roovy,RxJRuby
Jan.‘13
RxPY,RxPH
P
M
ar.‘13
RxKotlin
O
ct.‘13
RxSw
ift
Feb.‘15
Reactive Programming with RxSwift
ABOUT RX
▸ Event-driven
▸ Asynchronous
▸ Functional
▸ Common patterns
▸ Observer
▸ Iterator
▸ Cross-platform
LIFECYCLE OF AN OBSERVABLE SEQUENCE
▸ Next
1 2 3
LIFECYCLE OF AN OBSERVABLE SEQUENCE
▸ Next
tap tap tap
LIFECYCLE OF AN OBSERVABLE SEQUENCE
▸ Next
▸ Error
1 2 3
LIFECYCLE OF AN OBSERVABLE SEQUENCE
▸ Next
▸ Error
▸ Completed
1 2 3
LIFECYCLE OF AN OBSERVABLE SEQUENCE
▸ Next
▸ Error
▸ Completed
▸ dispose() / DisposeBag
1 2 3
RXSWIFT
▸RxSwift
▸RxCocoa
▸RxSwiftCommunity
▸ RxDataSources
SETUP
▸ Install ThisCouldBeUsButYouPlaying
▸ bit.ly/podsPlaygrounds
▸ gem install cocoapods-playgrounds
▸ Create RxSwiftPlayground
▸ pod playgrounds RxSwift
SETUP
//: Please build the scheme 'RxSwiftPlayground' first
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
import RxSwift
func exampleOf(description: String, action: Void -> Void) {
print("n--- Example of:", description, "---")
action()
}
--- Example of: just ---
Next(32)
Completed
CREATING & SUBSCRIBING
exampleOf("just") {
Observable.just(32)
}
.subscribe {
}
print($0)
--- Example of: just ---
Next(32)
Completed
exampleOf("just") {
Observable.just(32)
.subscribe { element in
print(element)
}
}
CREATING & SUBSCRIBING
--- Example of: just ---
32
exampleOf("just") {
_ = Observable.just(32)
.subscribeNext {
print($0)
}
}
CREATING & SUBSCRIBING
--- Example of: of ---
1
2
3
4
5
CREATING & SUBSCRIBING
exampleOf("of") {
Observable.of(1, 2, 3, 4, 5)
}
.subscribeNext {
print($0)
}
.dispose()
exampleOf("toObservable") {
}
--- Example of: toObservable ---
1
2
3
CREATING & SUBSCRIBING
let disposeBag = DisposeBag()
[1, 2, 3].toObservable()
.subscribeNext {
print($0)
}
.addDisposableTo(disposeBag)
CREATING & SUBSCRIBING
let string = BehaviorSubject(value: "Hello")
string.subscribe {
print($0)
}
.addDisposableTo(disposeBag)
exampleOf("BehaviorSubject") {
let disposeBag = DisposeBag()
}
string.on(.Next("World!"))
CREATING & SUBSCRIBING
let string = BehaviorSubject(value: "Hello")
string.subscribe {
print($0)
}
.addDisposableTo(disposeBag)
string.onNext("World!")
exampleOf("BehaviorSubject") {
let disposeBag = DisposeBag()
}
--- Example of: BehaviorSubject ---
Next(Hello)
Next(World!)
CREATING & SUBSCRIBING
let string = BehaviorSubject(value: "Hello")
string.subscribe {
print($0)
}
.addDisposableTo(disposeBag)
string.onNext("World!")
exampleOf("BehaviorSubject") {
let disposeBag = DisposeBag()
}
CREATING & SUBSCRIBING
--- Example of: Variable ---
Next(1)
Next(12)
Next(1234567)
Completed
number.value = 12
number.value = 1_234_567
exampleOf("Variable") {
let disposeBag = DisposeBag()
let number = Variable(1)
number.asObservable()
.subscribe {
print($0)
}
.addDisposableTo(disposeBag)
}
TRANSFORMING
--- Example of: map ---
1
4
9
Observable.of(1, 2, 3)
example("map") {
let disposeBag = DisposeBag()
}
.map { $0 * $0 }
.subscribeNext { print($0) }
.addDisposableTo(disposeBag)
TRANSFORMING
1
1
2
4
3
9
map { $0 * $0 }
TRANSFORMING
--- Example of: flatMap ---
Scott
Lori
Eric
exampleOf("flatMap") {
let disposeBag = DisposeBag()
}
struct Person {
var name: Variable<String>
}
let scott = Person(name: Variable("Scott"))
let lori = Person(name: Variable("Lori"))
let person = Variable(scott)
person.asObservable()
.flatMap {
$0.name.asObservable()
}
.subscribeNext {
print($0)
}
.addDisposableTo(disposeBag)
person.value = lori
scott.name.value = "Eric"
TRANSFORMING
--- Example of: flatMapLatest ---
Scott
Lori
exampleOf("flatMapLatest") {
let disposeBag = DisposeBag()
struct Person {
var name: Variable<String>
}
let scott = Person(name: Variable("Scott"))
let lori = Person(name: Variable("Lori"))
let person = Variable(scott)
person.asObservable()
.flatMapLatest {
$0.name.asObservable()
}
.subscribeNext {
print($0)
}
.addDisposableTo(disposeBag)
person.value = lori
scott.name.value = "Eric"
}
TRANSFORMING
exampleOf("flatMapLatest") {
let disposeBag = DisposeBag()
struct Person {
var name: Variable<String>
}
let scott = Person(name: Variable("Scott"))
let lori = Person(name: Variable("Lori"))
let person = Variable(scott)
person.asObservable()
.debug("person")
.flatMapLatest {
$0.name.asObservable()
}
.subscribeNext {
print($0)
}
.addDisposableTo(disposeBag)
person.value = lori
scott.name.value = "Eric"
}
--- Example of: flatMapLatest ---
2016-05-28 07:31:22.555: person -> subscribed
2016-05-28 07:31:22.556: person -> Event Next((Person #1)(nam...able<Swift.String>))
Scott
2016-05-28 07:31:22.557: person -> Event Next((Person #1)(nam...able<Swift.String>))
Lori
2016-05-28 07:31:22.560: person -> Event Completed
2016-05-28 07:31:22.560: person -> disposed
RXSWIFT OPERATORS
▸ Creating
asObservable
create
deferred
empty
error
toObservable
interval
never
just
of
range
repeatElement
timer
▸ Transforming
buffer
flatMap
flatMapFirst
flatMapLatest
map
scan
window
▸ Filtering
debounce / throttle
distinctUntilChanged
elementAt
filter
sample
skip
take
takeLast
single
▸ Conditional & Boolean
amb
skipWhile
skipUntil
takeUntil
takeWhile
▸ Mathematical &
Aggregate
concat
reduce
toArray
▸ Connectable
multicast
publish
refCount
replay
shareReplay
▸ Combining
merge
startWith
switchLatest
combineLatest
zip
▸ Error Handling
catch
retry
retryWhen
▸ Observing
delaySubscription
do / doOnNext
observeOn
subscribe
subscribeOn
timeout
using
debug
exampleOf("distinctUntilChanged") {
let disposeBag = DisposeBag()
let searchString = Variable("iOS")
searchString.asObservable()
.map { $0.lowercaseString }
.distinctUntilChanged()
.subscribeNext { print($0) }
.addDisposableTo(disposeBag)
searchString.value = "IOS"
searchString.value = "Rx"
searchString.value = "ios"
}
FILTERING
--- Example of: distinctUntilChanged ---
ios
rx
ios
exampleOf("combineLatest") {
let disposeBag = DisposeBag()
let number = PublishSubject<Int>()
let string = PublishSubject<String>()
Observable.combineLatest(number, string) { "($0) ($1)" }
.subscribeNext { print($0) }
.addDisposableTo(disposeBag)
number.onNext(1)
print("Nothing yet")
string.onNext("A")
number.onNext(2)
string.onNext("B")
string.onNext("C")
}
COMBINING
--- Example of: combineLatest ---
Nothing yet
1 A
2 A
2 B
2 C
exampleOf("takeWhile") {
[1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1].toObservable()
.takeWhile { $0 < 5 }
.subscribeNext { print($0) }
.dispose()
}
CONDITIONAL
--- Example of: takeWhile ---
1
2
3
4
MATHEMATICAL
--- Example of: _scan ---
11
13
16
20
25
exampleOf("scan") {
Observable.of(1, 2, 3, 4, 5)
.subscribeNext { print($0) }
.dispose()
}
.scan(10, accumulator: +)
MATHEMATICAL
--- Example of: _scan ---
11
13
16
20
25
exampleOf("scan") {
Observable.of(1, 2, 3, 4, 5)
.subscribeNext { print($0) }
.dispose()
}
.scan(10) { $0 + $1 }
ERROR HANDLING
--- Example of: error ---
A
exampleOf("error") {
enum Error: ErrorType { case A }
Observable<Int>.error(Error.A)
.subscribeError {
// Handle error
print($0)
}
.dispose()
}
NETWORKING
NETWORKING
NETWORKING
NETWORKING
Reactive Programming with RxSwift
NETWORKING
How about one more?
RXCOREDATA
RXCOREDATA
NETWORKING
How do I get started with RxSwift?
I’m glad you asked! !
LEARN RXSWIFT
▸This talk
▸RxSwift operators
RXSWIFT OPERATORS
LEARN RXSWIFT
▸This talk
▸RxSwift operators
▸RxCocoa
▸RxExample
RXSWIFT OPERATORS
RXSWIFT OPERATORS
LEARN RXSWIFT
▸This talk
▸RxSwift operators
▸RxCocoa
▸RxExample
▸RxCommunity
▸ github.com/ReactiveX/RxSwift
▸ reactivex.io
▸ rxmarbles.com
▸ slack.rxswift.org
▸ rx-marin.com
▸ as.ync.io
▸ github.com/scotteg/RxSwiftPlayer
▸ github.com/Artsy/eidolon
▸ lynda.com/Scott-Gardner/281956-1.html
WANT MORE RXSWIFT?
QUESTIONS?
THANK YOU!
Scott Gardner
@scotteg
scotteg.com
as.ync.io
bit.ly/scottOnLyndaDotCom

More Related Content

What's hot (20)

PDF
Oop assignment 02
MamoonKhan39
 
PDF
Introduction to RxJS
Brainhub
 
PDF
Intro to RxJava/RxAndroid - GDG Munich Android
Egor Andreevich
 
PDF
Swift Sequences & Collections
CocoaHeads France
 
PPTX
Rxjs ngvikings
Christoffer Noring
 
PDF
Reactive, component 그리고 angular2
Jeado Ko
 
PDF
RxJS101 - What you need to know to get started with RxJS tomorrow
Viliam Elischer
 
PPTX
Angular2 rxjs
Christoffer Noring
 
PDF
RxJS - The Reactive extensions for JavaScript
Viliam Elischer
 
PDF
RxJS 5 in Depth
C4Media
 
PDF
You will learn RxJS in 2017
名辰 洪
 
PDF
Understanding Asynchronous JavaScript
jnewmanux
 
PPTX
Luis Atencio on RxJS
Luis Atencio
 
PDF
RxJS - 封裝程式的藝術
名辰 洪
 
PPTX
Javascript Execution Context Flow
kang taehun
 
PPTX
Rxjs swetugg
Christoffer Noring
 
PDF
Map kit light
CocoaHeads France
 
PDF
Intro to Java 8 Closures (Dainius Mezanskas)
Kaunas Java User Group
 
PDF
Callbacks and control flow in Node js
Thomas Roch
 
PDF
Introduction to reactive programming & ReactiveCocoa
Florent Pillet
 
Oop assignment 02
MamoonKhan39
 
Introduction to RxJS
Brainhub
 
Intro to RxJava/RxAndroid - GDG Munich Android
Egor Andreevich
 
Swift Sequences & Collections
CocoaHeads France
 
Rxjs ngvikings
Christoffer Noring
 
Reactive, component 그리고 angular2
Jeado Ko
 
RxJS101 - What you need to know to get started with RxJS tomorrow
Viliam Elischer
 
Angular2 rxjs
Christoffer Noring
 
RxJS - The Reactive extensions for JavaScript
Viliam Elischer
 
RxJS 5 in Depth
C4Media
 
You will learn RxJS in 2017
名辰 洪
 
Understanding Asynchronous JavaScript
jnewmanux
 
Luis Atencio on RxJS
Luis Atencio
 
RxJS - 封裝程式的藝術
名辰 洪
 
Javascript Execution Context Flow
kang taehun
 
Rxjs swetugg
Christoffer Noring
 
Map kit light
CocoaHeads France
 
Intro to Java 8 Closures (Dainius Mezanskas)
Kaunas Java User Group
 
Callbacks and control flow in Node js
Thomas Roch
 
Introduction to reactive programming & ReactiveCocoa
Florent Pillet
 

Similar to Reactive Programming with RxSwift (20)

PDF
rx.js make async programming simpler
Alexander Mostovenko
 
PDF
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
GeeksLab Odessa
 
PDF
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Aziz Khambati
 
PDF
Rxjs kyivjs 2015
Alexander Mostovenko
 
PPTX
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PROIDEA
 
PDF
RxJava for Android - GDG DevFest Ukraine 2015
Constantine Mars
 
PPTX
Understanding reactive programming with microsoft reactive extensions
Oleksandr Zhevzhyk
 
PDF
State management in a GraphQL era
kristijanmkd
 
PDF
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Codemotion
 
PPTX
RxJava2 Slides
YarikS
 
PDF
Iniciación rx java
Elisa De Gregorio Medrano
 
PPTX
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
PDF
Let's discover React and Redux with TypeScript
Mathieu Savy
 
PDF
Reactive programming and RxJS
Ravi Mone
 
PPTX
Rx java in action
Pratama Nur Wijaya
 
PDF
No More Promises! Let's RxJS!
Ilia Idakiev
 
PDF
No more promises lets RxJS 2 Edit
Ilia Idakiev
 
PDF
RxSwift to Combine
Bo-Young Park
 
PDF
Reactive x
Gabriel Araujo
 
PPTX
Intro to Reactive Thinking and RxJava 2
JollyRogers5
 
rx.js make async programming simpler
Alexander Mostovenko
 
WebCamp:Front-end Developers Day. Александр Мостовенко "Rx.js - делаем асинхр...
GeeksLab Odessa
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Aziz Khambati
 
Rxjs kyivjs 2015
Alexander Mostovenko
 
4Developers 2015: Programowanie synchroniczne i asynchroniczne - dwa światy k...
PROIDEA
 
RxJava for Android - GDG DevFest Ukraine 2015
Constantine Mars
 
Understanding reactive programming with microsoft reactive extensions
Oleksandr Zhevzhyk
 
State management in a GraphQL era
kristijanmkd
 
Reactive Thinking in iOS Development - Pedro Piñera Buendía - Codemotion Amst...
Codemotion
 
RxJava2 Slides
YarikS
 
Iniciación rx java
Elisa De Gregorio Medrano
 
Async Redux Actions With RxJS - React Rally 2016
Ben Lesh
 
Let's discover React and Redux with TypeScript
Mathieu Savy
 
Reactive programming and RxJS
Ravi Mone
 
Rx java in action
Pratama Nur Wijaya
 
No More Promises! Let's RxJS!
Ilia Idakiev
 
No more promises lets RxJS 2 Edit
Ilia Idakiev
 
RxSwift to Combine
Bo-Young Park
 
Reactive x
Gabriel Araujo
 
Intro to Reactive Thinking and RxJava 2
JollyRogers5
 
Ad

Recently uploaded (20)

PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Ad

Reactive Programming with RxSwift