KEMBAR78
Reactive programming with RxSwift | PDF
Reactive programming
with RxSwift
Oleksandr Stepanov
iOS developer @Kromtech
01 What is reactive programming
TABLE OF CONTENTS
02 Frameworks for Swift & Obj-C
03 RxSwift basics
04 RxSwift/RxCocoa examples and demo
⼀一 Wikipedia
“Reactive programming is a declarative
programming paradigm concerned with data
streams and the propagation of change.”
Imperative programming
vs
Reactive programming
a := b + c
Reactive frameworks for Swift /
Objective-C
ReactiveCocoa RxSwift
ReactiveCocoa vs RxSwift
● Hot vs Cold producers/observables
○ RAC: Signal & SignalProducer
○ RxSwift: Observable
● Typed errors
○ RAC: Strictly typing
○ RxSwift: Swift.Error confirmance
● UI bindings
○ + RxSwift
● Objective-C support
○ + RAC (ReactiveObjC)
ReactiveX
frameworks family
RxJava
RxScala
RxJs
Rx.Net
RxSwift
and more
RxSwift basics
● Observer subscribes to an Observable.
● Each subscription starts
with .subscribe(...)
● Each subscription must be disposed
Subscribe consist of:
● onNext
is called when Observable emits an item
● onError
Observable failed, and it will stop emitting
● onComplete
Observable will not emit anything more
Subscription termination with Disposable
● Subscribe function returns Disposable
● Recommended practice is not to dispose it
manually, but use DisposeBag entity instead
● onDispose callback called just before dispose
Subjects
“A Subject is a sort of bridge or proxy that
acts both as an оbserver and as an
Observable”
Relays
● Relays never complete and never errors
● Part of RxRelay framework
● PublishRelay and BehaviorRelay
available
Schedulers
● Multithreading concept for Rx
● By default, an Observable and the chain of operators
that you apply to it will do its work and will notify its
observers on the same thread on which its Subscribe
method is called.
● subscribeOn() and observeOn()
map
filter
concat
zip
Operators
and more
debounce
skip
merge
take
SHOW ME THE CODE!
It’s demo time
Pros
● Declarative code instead of imperative
● Observable pattern on steroids
● Must have for popular UI architectures
nowadays (MVVM, VIPER, RIBs etc.)
Cons
● Reduced performance (increased call stack)
● Hard to debug
● IDE syntax highlight stuck regularly
References
● ReactiveX
● RxSwift getting started
● Demo project (MVVM+Router)
Thank you!

Reactive programming with RxSwift