RxSwift
Languages
● Java: RxJava
● JavaScript: RxJS
● C#: Rx.NET
● C#(Unity): UniRx
● Scala: RxScala
● Clojure: RxClojure
● C++: RxCpp
● Lua: RxLua
● Ruby: Rx.rb
● Python: RxPY
● Go: RxGo
● Groovy: RxGroovy
● JRuby: RxJRuby
● Kotlin: RxKotlin
● Swift: RxSwift
● PHP: RxPHP
● Elixir: reaxive
● Dart: RxDart
What is RxSwift
- Multi-platform API called Rx
- Asynchronous programming
- Event sequences
- Composable operators
- Сombination of the best ideas from the Observer
pattern, the Iterator pattern, and functional
programming
Misconceptions
- You must be a functional programming wizard
- It’s all or nothing
- It’s too slow for mobile development
Asynchronous code
show / hide
user input
select element
synchronization
network data
portrait / landscape
update storage
tap
Complexity of async code
- States, shared states
- Side effects
- Combining, transforming, filtering async operations
Asynchronous code
Controller
NotificationCenter
Other Controller
closure
DataSource
Delegate
GCD
switch queues
Observable
true false
Observable<Bool>
true false true
0 1 2 3 0
Observable<Int>
Lifecycle of observable
true false true false true
0 1 2 3
Observable
0 1 2 3 0
Observable<Int>
Observable
0 1 2 3 0
Observable<Int>
Observable<Int> Observer 2
Observer 3
Observer 1
0, 1, 2, 3, 0
0, 1, 2, 3, 0
0, 1, 2, 3, 0
Operators
Observable<GMSVisibleRegion>
debounce(0.3)
Output: value0, value1, value2
filter { $0.isValid }
Output: value2
map { $0.toAPIStringBbox }
Output: value2
flatMap { mapMarkersInBbox($0) }
Output: bbox
Output: [MapMarker]
Subscriber
Updating UI
C Cr
Observable<String>
Cry CrysCrys
Updating UI
C Cr
Observable<String>
Cry CrysCrys
testLabel.text = string
Updating UI
C Cr
Observable<String>
Cry CrysCrys
testLabel.text = string
string.bindTo(testLabel)
Updating UI
[Item]
Observable<[Item]>
Crys
dataSourceVar = items
tableView.reloadData()
items.bindTo(tableView)
JSON [Item]
Filtering
Combining
Transforming
RxSwift vs RxCocoa
RxSwift
map, debounce,
filter, etc.
RxPython
RxCocoa
bindTo, Driver,
UISearchBar.rx,
UISwitch.rx
UIKit / Cocoa
specific APIs
RxScala RxKotlin
Rx API
Demo!
Traits
RxSwift
- Single
- Completable
- Maybe
RxCocoa
- Driver
- ControlProperty / ControlEvent
Traits
Single
- Emits exactly one element, or an error
- Doesn't share side effects
Traits
Completable
- Emits zero elements
- Emit a completion event or an error
- Doesn't share side effects
Traits
Maybe
- Emits either a completed event, a single element or
an error
- Doesn't share side effects
RxCocoa specific Traits
Driver
- Can't error out
- Observe occurs on main scheduler
- Shares side effects
(shareReplayLatestWhileConnected)
RxCocoa specific Traits
ControlProperty / ControlEvent
- it never fails
- shareReplay(1) behavior
- complete sequence on control being deallocated
- it never errors out
- it delivers events on MainScheduler.instance
Tests
Tests
Pros. Development
- Asynchrony is simplified with Declarative Code
Pros. Development
- Asynchrony is simplified with Declarative Code
- Cleaner Code & Architectures
Pros. Development
- Asynchrony is simplified with Declarative Code
- Cleaner Code & Architectures
- Code testability (using MVVM)
Pros. Development
- Asynchrony is simplified with Declarative Code
- Cleaner Code & Architectures
- Code testability (using MVVM)
- Built-in solutions & Composable components
Pros. Development
- Asynchrony is simplified with Declarative Code
- Cleaner Code & Architectures
- Code testability (using MVVM)
- Built-in solutions & Composable components
- Time-tested multiplatform technology
Cons. Development
- Efforts to learn a framework
Cons. Development
- Efforts to learn a framework
- Possible leg-shots
Cons. Development
- Efforts to learn a framework
- Possible leg-shots
- XCode still fucks you up
Pros. Business
- Less bugs and risks – less time to deliver
Pros. Business
- Less bugs and risks – less time to deliver
- Easier to create a great UX
Pros. Business
- Less bugs and risks – less time to deliver
- Easier to create a great UX
- Multiplatform
Cons. Business
- Expenses of team training
- Harder to find a developer
References
- https://github.com/ReactiveX/RxSwift
- http://rxmarbles.com/
- RxMarbles iOS App
- http://community.rxswift.org/
- RxSwift operators mindmap
RxDataSource

RxSwift