RxSwift
The Power in your fingers
Favara Vincenzo
UI interactions between event
and validations
UI
Witch db use depending of your
operations
Data Storage
Thinking as modular
architecture to manage the
app complexity
Architecture
Sometimes network calls
need to be triggered in
cascade
Networking
Starting new Mobile App project
What’s the most relevant troubles starting a new mobile app?
Architecture complexity
Apple SDK offers a huge variety of APIs
Using Delegates requires you
to adopt different patterns for
notifications, closures,
callbacks...
Rx heros family are here for you.
They offer an alternative approach that is both clear and concise, to manage
asynchronous tasks and events.
Acting to the configuration way instead to classic way
ReactiveX Heros
ReactiveX is a library for composing asynchronous events by using observable sequences.
RxJava
RxJs
RxSwift
RxPHP
Rx.NET
RxKotlin
Hello!
Let me introduce myself
rxswift.slack.com @rxswift
I am Ironman
“I am a reactive programming library for iOS.
I make it easy to program dynamic apps that
respond to data changes and user events by
using observables.”
github.com/ReactiveX/RxSwift
Simplified Multi-thread
Switching Main/Backgrounds threads in one line
Multi platform
Rx exists for the most used languages
Huge communities
Communities are actives in socials too
Everything is observable
Observable is a asynchronous sequence
Composable & Reusable
composed by structures and operators
Async is Declarative
definitions are immutable, data changes
Rx SuperPowers
Infinity gountlet in your hand!
What’s an Observable?
It’s a async sequence or stream of emitted items
Subscription Events:
- onNext
- onError
- onComplete
Composable & Reusable
RxSwift provides Structures and Operators
● The structures provide different ways
of publishing information.
● The operations transform, decorate,
compose, etc, the information.
You can check here:
http://reactivex.io/documentation/operators.html
PublishSubject
Start empty
Emit new next event to new
subscribers
ReplaySubject
Start empty with a buffer size
Replays buffer to new subscribers
BehaviorSubject
Start with initial value
Replays initial / latest value to new
subscribers
Structures
Different ways of publishing information
Create Transform Filter Combine Error Utility
Operators
Some of category operators
● create
● just
● from
● flatMap
● map
● groupBy
● filter
● distinct
● ignoreElements
● combineLatest
● merge
● zip
● catch
● retry
● subscribe
● observeOn
● delay
http://reactivex.io/documentation/operators.html
Async is Declarative
Definitions are immutable, data changes
Declarative code enables you to
describe a complex async
workflow at a high level in a few
lines passing from traditional
nested callbacks, delegates,
notifications, kvo, etc to a
configured data steps
Tap stream
Items stream
Response stream
Request stream
Simplified Multi-threading
Switching on different threads is easier
There are situations in which you need to
perform tasks in different threads.
You can easy listen to an event on the
main thread and react in background and
switch back to the main thread to show
the results.
Tap stream
Items stream
Response stream
Request stream
observeOn( .background)
observeOn( .main)
Reactive programming is a way of working, it’s a design pattern, or a set of them for all that matters. The same standardisation
comes in different languages and platforms. So If you learn Reactive Programming in Swift, you can take it with you to another
platform and language.
Multi-platform
Rx is different languages with a huge community.
RxJava
RxSwift
RxJs
Rx.NET
UniRx
RxScala
RxCpp
RxLua
Rx.rb
RxPY
RxGo
RxGroovy
RxKotlin
RxDart
RxPHP
http://reactivex.io/languages.html
RxSwift world is huge so you can have some troubles
during your way.
Here there are the most dangerous problems you can find
Wrong superpower use
With great power comes great responsibility
Learning curve
The learning
process is
intimidating at
the beginning.
Memory leak
Be careful with
self references
inside closures
Debugging
Stack traces are a
lot bigger,
It’s hard to find
crash/bug
reasons
Abusing
Don’t use for
everything if you
don’t need it
Avoid Memory leak
Avoid the strong reference cycle inside closures
If the closure is owned by scope and not
by the class (example: in-line closures) you
do not have to use [weak self] because
it will be released when the scope is left.
If the closure is passed in it may or may
not be owned by the class (a property for
example) and it is prudent to use [weak
self] incase it is owned by the class.
Debugging in RxSwift
Is it possible debug easy?
First: What is a Fast-Fish? Alive
or dead a fish is technically fast,
when it is connected with an
occupied ship or boat.
Let’s code...
Try to write an example
{ }
Use Cases
Using RxSwift in a common use cases:
- Perform and display a research
- Connect a single api call to two distinct collections
- Set up a chat gui
Call BE after
300ms each time
type a new letter
and in the case
cancel previous
call
For each result
found create a cell
in the table view if
exist value
When you create an ios app with a search toolbar, you are going to solve some common problems like calling BE after
waiting time and display results in a table view
Search and results
Try to figure out the problem in the use case
RxSwift
Operators:
- debounce
- distinct
- observeOn
- flatMap
- bind
- dispose
When you create an ios app with more than one only
collection view, you could have necessity to split your
retrieved data to both collection view
- Steps:
● Retrieve Data Movie with all own actors inside
● Save Movie on top collection view and all actors
in main collection view
Two collections
Try to figure out the problem in the use case
RxSwift
Operators:
- observeOn
- flatMap
- share
- bind
- dispose
Listen for new
received
messages
For each one put a
dots cell before it
appears disabling
user input sending
When you create an ios app with a chat system inside, you are going to solve some common problems like the messages
retrieving and receiving
Messages in a chat
Try to figure out the problem in the use case
RxSwift
Operators:
- observeOn
- map
- concatMap
- delay
- flatMap
- dispose
RxSwift
Libs:
- Alamofire
- RxAlamofire
https://github.com/RxSwiftCommunity/RxAlamofire
95%
WRITE A TITLE HERE
First: What is a Fast-Fish? Alive
or dead a fish is technically fast,
when it is connected with an
occupied ship or boat, by any
medium at all controllable by
the occupant oR
Pratics
Reactive thinking way
Studying RxSwift components and operators
You want to refactor yesterday’s code
Personal Experience
What I learned and what’s my feeling about RxSwift
Thank You!
Favara Vincenzo

Rx Swift

  • 1.
    RxSwift The Power inyour fingers Favara Vincenzo
  • 2.
    UI interactions betweenevent and validations UI Witch db use depending of your operations Data Storage Thinking as modular architecture to manage the app complexity Architecture Sometimes network calls need to be triggered in cascade Networking Starting new Mobile App project What’s the most relevant troubles starting a new mobile app?
  • 3.
    Architecture complexity Apple SDKoffers a huge variety of APIs Using Delegates requires you to adopt different patterns for notifications, closures, callbacks...
  • 4.
    Rx heros familyare here for you. They offer an alternative approach that is both clear and concise, to manage asynchronous tasks and events. Acting to the configuration way instead to classic way ReactiveX Heros ReactiveX is a library for composing asynchronous events by using observable sequences. RxJava RxJs RxSwift RxPHP Rx.NET RxKotlin
  • 5.
    Hello! Let me introducemyself rxswift.slack.com @rxswift I am Ironman “I am a reactive programming library for iOS. I make it easy to program dynamic apps that respond to data changes and user events by using observables.” github.com/ReactiveX/RxSwift
  • 6.
    Simplified Multi-thread Switching Main/Backgroundsthreads in one line Multi platform Rx exists for the most used languages Huge communities Communities are actives in socials too Everything is observable Observable is a asynchronous sequence Composable & Reusable composed by structures and operators Async is Declarative definitions are immutable, data changes Rx SuperPowers Infinity gountlet in your hand!
  • 7.
    What’s an Observable? It’sa async sequence or stream of emitted items Subscription Events: - onNext - onError - onComplete
  • 8.
    Composable & Reusable RxSwiftprovides Structures and Operators ● The structures provide different ways of publishing information. ● The operations transform, decorate, compose, etc, the information. You can check here: http://reactivex.io/documentation/operators.html
  • 9.
    PublishSubject Start empty Emit newnext event to new subscribers ReplaySubject Start empty with a buffer size Replays buffer to new subscribers BehaviorSubject Start with initial value Replays initial / latest value to new subscribers Structures Different ways of publishing information
  • 10.
    Create Transform FilterCombine Error Utility Operators Some of category operators ● create ● just ● from ● flatMap ● map ● groupBy ● filter ● distinct ● ignoreElements ● combineLatest ● merge ● zip ● catch ● retry ● subscribe ● observeOn ● delay http://reactivex.io/documentation/operators.html
  • 11.
    Async is Declarative Definitionsare immutable, data changes Declarative code enables you to describe a complex async workflow at a high level in a few lines passing from traditional nested callbacks, delegates, notifications, kvo, etc to a configured data steps Tap stream Items stream Response stream Request stream
  • 12.
    Simplified Multi-threading Switching ondifferent threads is easier There are situations in which you need to perform tasks in different threads. You can easy listen to an event on the main thread and react in background and switch back to the main thread to show the results. Tap stream Items stream Response stream Request stream observeOn( .background) observeOn( .main)
  • 13.
    Reactive programming isa way of working, it’s a design pattern, or a set of them for all that matters. The same standardisation comes in different languages and platforms. So If you learn Reactive Programming in Swift, you can take it with you to another platform and language. Multi-platform Rx is different languages with a huge community. RxJava RxSwift RxJs Rx.NET UniRx RxScala RxCpp RxLua Rx.rb RxPY RxGo RxGroovy RxKotlin RxDart RxPHP http://reactivex.io/languages.html
  • 14.
    RxSwift world ishuge so you can have some troubles during your way. Here there are the most dangerous problems you can find Wrong superpower use With great power comes great responsibility Learning curve The learning process is intimidating at the beginning. Memory leak Be careful with self references inside closures Debugging Stack traces are a lot bigger, It’s hard to find crash/bug reasons Abusing Don’t use for everything if you don’t need it
  • 15.
    Avoid Memory leak Avoidthe strong reference cycle inside closures If the closure is owned by scope and not by the class (example: in-line closures) you do not have to use [weak self] because it will be released when the scope is left. If the closure is passed in it may or may not be owned by the class (a property for example) and it is prudent to use [weak self] incase it is owned by the class.
  • 16.
    Debugging in RxSwift Isit possible debug easy? First: What is a Fast-Fish? Alive or dead a fish is technically fast, when it is connected with an occupied ship or boat.
  • 17.
    Let’s code... Try towrite an example { }
  • 18.
    Use Cases Using RxSwiftin a common use cases: - Perform and display a research - Connect a single api call to two distinct collections - Set up a chat gui
  • 19.
    Call BE after 300mseach time type a new letter and in the case cancel previous call For each result found create a cell in the table view if exist value When you create an ios app with a search toolbar, you are going to solve some common problems like calling BE after waiting time and display results in a table view Search and results Try to figure out the problem in the use case
  • 20.
    RxSwift Operators: - debounce - distinct -observeOn - flatMap - bind - dispose
  • 21.
    When you createan ios app with more than one only collection view, you could have necessity to split your retrieved data to both collection view - Steps: ● Retrieve Data Movie with all own actors inside ● Save Movie on top collection view and all actors in main collection view Two collections Try to figure out the problem in the use case
  • 22.
  • 23.
    Listen for new received messages Foreach one put a dots cell before it appears disabling user input sending When you create an ios app with a chat system inside, you are going to solve some common problems like the messages retrieving and receiving Messages in a chat Try to figure out the problem in the use case
  • 24.
    RxSwift Operators: - observeOn - map -concatMap - delay - flatMap - dispose
  • 25.
  • 26.
    95% WRITE A TITLEHERE First: What is a Fast-Fish? Alive or dead a fish is technically fast, when it is connected with an occupied ship or boat, by any medium at all controllable by the occupant oR Pratics Reactive thinking way Studying RxSwift components and operators You want to refactor yesterday’s code Personal Experience What I learned and what’s my feeling about RxSwift
  • 27.