SlideShare una empresa de Scribd logo
1 de 52
Descargar para leer sin conexión
RxSwift
By Sally Ahmed
Agenda
● Functional Programming
● Reactive Programming
● What is RxSwift ?
● Why RxSwift
● RxSwift - Observable
○ Lifecycle of an observable
● Install RxSwift - Example
Agenda - continue
● Creating observables*
○ Just
○ Of
○ Create
● Hot vs Cold Observable
● Scheduler
○ Subscribe on
○ Observer on
● Operators *
○ Transforming Operators
■ Map
■ Scan
Agenda - continue
● Operators *
○ Filtering Operators
■ Filter
■ Debounce
● Subjects
○ PublishSubject
○ BehaviorSubject
○ ReplaySubject
● MVVM with RxSwift
Functional Programming
Functional Programming
First and foremost, functional programming is not a language or a syntax¹ , but rather a
programming paradigm — a way of solving problems by decomposing complicated processes
into simpler ones
● Functional Programming Concepts
○ immutable state
○ lack of side effects
Functional Programming - Continue
Functional Programming - Continue
Reactive Programming
Reactive Programming is an asynchronous programming paradigm concerned with data streams
and the propagation of change. ReactiveX or Rx is the most popular API for reactive programming. It's
built on the ideologies of the Observable Pattern, Iterator Pattern, and Functional Programming
What is RxSwift ?
RxSwift is a library for composing asynchronous and event-based code by using observable
sequences and functional style operators, allowing for parameterized execution via
schedulers.
in its essence, simplifies developing asynchronous programs by allowing your code to react to
new data and process it in sequential, isolated manner.
Why RxSwift
UI programming is mostly about reacting to some asynchronous tasks. We’re taught to implement that
with observer patterns: I’m pretty sure you’re familiar with delegates by now. Delegating is a cool pattern,
but it gets really tiring…
RxSwift Observable
Life cycle of Observable
- Next
- Error
- Complete
- Disposing and terminating
Creating observables
Creating observables
Creating observables
Creating observables
UI Example
● Install RxSwift - Example
● Switch on- off example
● UITableView
Hot vs Cold Observables
When the data is produced by the Observable itself, we call it a cold Observable.
When the data is produced outside the Observable, we call it a hot Observable.
Scheduler
it’s important to understand what they are — and what they are not. To summarize,
a scheduler is a context where a process takes place. This context can be a thread,
a dispatch queue or similar entities, or even an NSOperation which is used inside
the OperationQueueScheduler.
Here’s a good example as to how schedulers can be used:
Using subscribeOn
When you want to actually observe an
observable, you subscribe to it. This determines where the original processing will
happen. If subscribeOn is not called, then RxSwift automatically uses the current
thread:
Using subscribeOn - Contunie
Using observeOn
Observing is one of the three fundamental concepts of Rx. It involves an entity
producing events, and an observer for those events. In this case, and in opposition
to subscribeOn, the operator observeOn changes the scheduler where the
observation happens.
Scheduler
Scheduler - example
Needed Example
Create collectionview for exchange currency convertor from EURO
API -> https://api.exchangeratesapi.io/latest
Email: -> eng.sally.ahmed@gmail.com
Operators - Transforming Operators
● Map
Operators - Transforming Operators
● Scan
Operators - Filtering Operators
● Filter
Operators - Filtering Operators
● Debounce
Skipping operators - Skip
Skipping operators - Skip
Skipping operators - SkipWhile
Taking operators
Distinct operators
Throttling
Example
● Different between debounce and Throttle
Driver
Driver is a special observable with the same constraints as explained before, so it
can’t error out. All processes are ensured to execute on the main thread, which
avoids making UI changes on background threads.
Driver - Continue
ControlEvent
ControlEvent is used to listen to a certain event of the UI component, like the
pressof the “Return” button on the keyboard while editing a text field. A control
event isavailable if the component uses UIControlEvents to keep track of its
current status.
Subjects
You’ve gotten a handle on what an observable is, how you create one, how to
subscribe to it, and how to dispose of things when you’re done. Observables are a
fundamental part of RxSwift, but a common need when developing apps is to
manually add new values onto an observable at runtime that will then be emitted to
subscribers. What you want is something that can act as both an observable and
as an observer. And that something is called a Subject.
Subjects - PublishSubject
Subjects - BehaviorSubject
Subjects - ReplaySubject
Architecture design
Why ?
● Scalability
● Maintainability
● Testability
Solid Principles
● Single Responsibility Principle
○ Every part in the application should do one and only one thing, starting
from the level of methods and functions, to classes, even to packages …
everything should have only one reason to change
Solid Principles
● Open Closed Principle
○ Every class should be open for extension / inheritance, but closed for
modification, which means that if we have a class that makes something,
and we want to make this class do another thing, we should not modify
this class, but we can create a subclass that does this new thing, or we
can make extension functions for that class
Solid Principles
● Liskov Substitution Principle
○ When we use a subclass instead of the superclass, this behavior should
not break the software, in other words, we do not override methods in our
subclass and make it crash or misbehave when used
Solid Principles
● Interface Segregation Principle
○ Never declare methods in an interface that one of it's implementing
classes won’t need to override, same goes for abstract classes
Solid Principles
● Dependency Inversion Principle
○ Try to deal with the parent types as much as possible, try to deal with
interfaces or abstract classes as much as possible, this will make the
software more flexible and easy to change
Architecture design
Architecture design - MVVM

Más contenido relacionado

La actualidad más candente

How to add Fixtures into your Django app with Mixer
How to add Fixtures into your Django app with MixerHow to add Fixtures into your Django app with Mixer
How to add Fixtures into your Django app with MixerGuinsly Mondesir
 
Pure functions using Javascript.
Pure functions using Javascript.Pure functions using Javascript.
Pure functions using Javascript.Leon Maia
 
Hibernate concurrency
Hibernate concurrencyHibernate concurrency
Hibernate concurrencypriyank09
 
MVVM and RxJava – the perfect mix
MVVM and RxJava – the perfect mixMVVM and RxJava – the perfect mix
MVVM and RxJava – the perfect mixFlorina Muntenescu
 

La actualidad más candente (6)

Callback Function
Callback FunctionCallback Function
Callback Function
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
How to add Fixtures into your Django app with Mixer
How to add Fixtures into your Django app with MixerHow to add Fixtures into your Django app with Mixer
How to add Fixtures into your Django app with Mixer
 
Pure functions using Javascript.
Pure functions using Javascript.Pure functions using Javascript.
Pure functions using Javascript.
 
Hibernate concurrency
Hibernate concurrencyHibernate concurrency
Hibernate concurrency
 
MVVM and RxJava – the perfect mix
MVVM and RxJava – the perfect mixMVVM and RxJava – the perfect mix
MVVM and RxJava – the perfect mix
 

Similar a RxSwift

Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopMohammad Shawahneh
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
 
Serverless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From ProductionServerless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From ProductionSteve Hogg
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Ramith Jayasinghe
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"IT Event
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in AngularKnoldus Inc.
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architectureMilan Patel
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in ActionKnoldus Inc.
 
Apache Cassandra Lunch #102: Choreography vs Orchestration
Apache Cassandra Lunch #102: Choreography vs OrchestrationApache Cassandra Lunch #102: Choreography vs Orchestration
Apache Cassandra Lunch #102: Choreography vs OrchestrationAnant Corporation
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIVisual Engineering
 
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsEffects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsManuel Rivero
 
Introduction to Unit Testing
Introduction to Unit TestingIntroduction to Unit Testing
Introduction to Unit TestingSwanky Hsiao
 
Retrofitting a legacy SPA to use a functional architecture
Retrofitting a legacy SPA to use a functional architectureRetrofitting a legacy SPA to use a functional architecture
Retrofitting a legacy SPA to use a functional architectureManuel Rivero
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesWalking Tree Technologies
 
Performance Test Automation With Gatling
Performance Test Automation  With GatlingPerformance Test Automation  With Gatling
Performance Test Automation With GatlingKnoldus Inc.
 
Short journey into the serverless world
Short journey into the serverless worldShort journey into the serverless world
Short journey into the serverless worldScott van Kalken
 

Similar a RxSwift (20)

Object Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshopObject Oriented, Design patterns and data modelling worshop
Object Oriented, Design patterns and data modelling worshop
 
Why Concurrency is hard ?
Why Concurrency is hard ?Why Concurrency is hard ?
Why Concurrency is hard ?
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Serverless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From ProductionServerless - DevOps Lessons Learned From Production
Serverless - DevOps Lessons Learned From Production
 
Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architecture
 
Akka (1)
Akka (1)Akka (1)
Akka (1)
 
CQRS and Event Sourcing in Action
CQRS and Event  Sourcing in ActionCQRS and Event  Sourcing in Action
CQRS and Event Sourcing in Action
 
Apache Cassandra Lunch #102: Choreography vs Orchestration
Apache Cassandra Lunch #102: Choreography vs OrchestrationApache Cassandra Lunch #102: Choreography vs Orchestration
Apache Cassandra Lunch #102: Choreography vs Orchestration
 
Workshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte IIIWorkshop 14: AngularJS Parte III
Workshop 14: AngularJS Parte III
 
Effects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAsEffects, Coeffects & Subscriptions: a pit of success for SPAs
Effects, Coeffects & Subscriptions: a pit of success for SPAs
 
Introduction to Unit Testing
Introduction to Unit TestingIntroduction to Unit Testing
Introduction to Unit Testing
 
Retrofitting a legacy SPA to use a functional architecture
Retrofitting a legacy SPA to use a functional architectureRetrofitting a legacy SPA to use a functional architecture
Retrofitting a legacy SPA to use a functional architecture
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
Gatling
Gatling Gatling
Gatling
 
Performance Test Automation With Gatling
Performance Test Automation  With GatlingPerformance Test Automation  With Gatling
Performance Test Automation With Gatling
 
Short journey into the serverless world
Short journey into the serverless worldShort journey into the serverless world
Short journey into the serverless world
 
JavaFX in Action Part I
JavaFX in Action Part IJavaFX in Action Part I
JavaFX in Action Part I
 

Último

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 

Último (20)

Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 

RxSwift

  • 2. Agenda ● Functional Programming ● Reactive Programming ● What is RxSwift ? ● Why RxSwift ● RxSwift - Observable ○ Lifecycle of an observable ● Install RxSwift - Example
  • 3. Agenda - continue ● Creating observables* ○ Just ○ Of ○ Create ● Hot vs Cold Observable ● Scheduler ○ Subscribe on ○ Observer on ● Operators * ○ Transforming Operators ■ Map ■ Scan
  • 4. Agenda - continue ● Operators * ○ Filtering Operators ■ Filter ■ Debounce ● Subjects ○ PublishSubject ○ BehaviorSubject ○ ReplaySubject ● MVVM with RxSwift
  • 6. Functional Programming First and foremost, functional programming is not a language or a syntax¹ , but rather a programming paradigm — a way of solving problems by decomposing complicated processes into simpler ones ● Functional Programming Concepts ○ immutable state ○ lack of side effects
  • 9. Reactive Programming Reactive Programming is an asynchronous programming paradigm concerned with data streams and the propagation of change. ReactiveX or Rx is the most popular API for reactive programming. It's built on the ideologies of the Observable Pattern, Iterator Pattern, and Functional Programming
  • 10. What is RxSwift ? RxSwift is a library for composing asynchronous and event-based code by using observable sequences and functional style operators, allowing for parameterized execution via schedulers. in its essence, simplifies developing asynchronous programs by allowing your code to react to new data and process it in sequential, isolated manner.
  • 11. Why RxSwift UI programming is mostly about reacting to some asynchronous tasks. We’re taught to implement that with observer patterns: I’m pretty sure you’re familiar with delegates by now. Delegating is a cool pattern, but it gets really tiring…
  • 13. Life cycle of Observable - Next - Error - Complete - Disposing and terminating
  • 18. UI Example ● Install RxSwift - Example ● Switch on- off example ● UITableView
  • 19. Hot vs Cold Observables When the data is produced by the Observable itself, we call it a cold Observable. When the data is produced outside the Observable, we call it a hot Observable.
  • 20. Scheduler it’s important to understand what they are — and what they are not. To summarize, a scheduler is a context where a process takes place. This context can be a thread, a dispatch queue or similar entities, or even an NSOperation which is used inside the OperationQueueScheduler. Here’s a good example as to how schedulers can be used:
  • 21. Using subscribeOn When you want to actually observe an observable, you subscribe to it. This determines where the original processing will happen. If subscribeOn is not called, then RxSwift automatically uses the current thread:
  • 23. Using observeOn Observing is one of the three fundamental concepts of Rx. It involves an entity producing events, and an observer for those events. In this case, and in opposition to subscribeOn, the operator observeOn changes the scheduler where the observation happens.
  • 26. Needed Example Create collectionview for exchange currency convertor from EURO API -> https://api.exchangeratesapi.io/latest Email: -> eng.sally.ahmed@gmail.com
  • 27. Operators - Transforming Operators ● Map
  • 28. Operators - Transforming Operators ● Scan
  • 29. Operators - Filtering Operators ● Filter
  • 30. Operators - Filtering Operators ● Debounce
  • 33. Skipping operators - SkipWhile
  • 37. Example ● Different between debounce and Throttle
  • 38. Driver Driver is a special observable with the same constraints as explained before, so it can’t error out. All processes are ensured to execute on the main thread, which avoids making UI changes on background threads.
  • 40. ControlEvent ControlEvent is used to listen to a certain event of the UI component, like the pressof the “Return” button on the keyboard while editing a text field. A control event isavailable if the component uses UIControlEvents to keep track of its current status.
  • 41. Subjects You’ve gotten a handle on what an observable is, how you create one, how to subscribe to it, and how to dispose of things when you’re done. Observables are a fundamental part of RxSwift, but a common need when developing apps is to manually add new values onto an observable at runtime that will then be emitted to subscribers. What you want is something that can act as both an observable and as an observer. And that something is called a Subject.
  • 45. Architecture design Why ? ● Scalability ● Maintainability ● Testability
  • 46. Solid Principles ● Single Responsibility Principle ○ Every part in the application should do one and only one thing, starting from the level of methods and functions, to classes, even to packages … everything should have only one reason to change
  • 47. Solid Principles ● Open Closed Principle ○ Every class should be open for extension / inheritance, but closed for modification, which means that if we have a class that makes something, and we want to make this class do another thing, we should not modify this class, but we can create a subclass that does this new thing, or we can make extension functions for that class
  • 48. Solid Principles ● Liskov Substitution Principle ○ When we use a subclass instead of the superclass, this behavior should not break the software, in other words, we do not override methods in our subclass and make it crash or misbehave when used
  • 49. Solid Principles ● Interface Segregation Principle ○ Never declare methods in an interface that one of it's implementing classes won’t need to override, same goes for abstract classes
  • 50. Solid Principles ● Dependency Inversion Principle ○ Try to deal with the parent types as much as possible, try to deal with interfaces or abstract classes as much as possible, this will make the software more flexible and easy to change