You may have heard about reactive programming. Maybe even checked out RxSwift. But if you're not using it in your daily development, you're really missing out! Rx decimates the boilerplate code you'd have to write to do the same things in the traditional, imperative manner. And, in this day and age where the answer to supporting multiple platforms has given rise to using "lowest common denominator" cross-platform development technologies, Rx shifts the focus back to developers who want to stay true to their platform of choice, by unifying the patterns and operators used to write app code on any platform. Come see how reactive programming with RxSwift will change your life and make you richer than your wildest dreams.
14. 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
37. 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"
38. 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"
}
39. 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
40. 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