RxSwift整理

RxSwift

Definition:
Use concept of Observer pattern and sequence operators, let us handle asynchronous data/event together in a declarative manner

The tools(i.e. objects) provided:

  • Observable
  • Operators
  • Subject
  • Scheduler

Observable

Definition:
The object that emits data/event asynchronously

Functions:

  • subscribe/unsubscribe
  • Manage life time

Operators

Definition:
Provide the way to handle data collection after receiving data/event from observable

Functions:

  • Creating Observables
  • Transforming Observables
  • Filtering Observables
  • Combining Observables
  • Error Handling Operators
  • Observable Utility Operators
  • Conditional and Boolean Operators
  • Mathematical and Aggregate Operators
  • Backpressure Operators
  • Connectable Observable Operators

Subject

Definition:
Acts both as an observer and as an Observable. Because it is an observer, it can subscribe to one or more Observables, and because it is an Observable, it can pass through the items it observes by reemitting them, and it can also emit new items.

Scheduler

Definition:
introduce multithreading into your cascade of Observable operators, you can do so by instructing those operators (or particular Observables) to operate on particular Schedulers.

Operators for specifying which thread:

  • SubscribeOn (p.s. specifying a different Scheduler on which the Observable should operate)
  • ObserveOn (p.s. specifies a different Scheduler that the Observable will use to send notifications to its observers.)

%d