RxSwift CH03. Subject

sinclair
Nov 3, 2020

--

What are Subjects?

  1. What are subjects?

Subjects acts as both an observable and an observer. The subject received events, and each time it receives an event, it turned around and emitted it to its subscriber.

Let’s see the sample code written in the book.

(Code)

There are four types of subjects in RxSwift:

  1. PublishSubject : Starts empty and only emits new elements to its subscribers.
  2. BehaviorSubject: Starts with an initial value and replays it or the latest elements to new subscribers.
  3. ReplaySubject: Initialized with a buffer size and will remain a buffer of elements up to that size and replay it to new subscribers.
  4. Variable: Wrap a BehaviorSubject, preservers its current value as state, and replays only the latest/initial value to new subscribers.

Those are the simple definitions of those four subject types in RxSwift according to the textbook. We are going to see those types in detail.

  1. PublishSubject : Starts empty and only emits new elements to its subscribers.

In this diagram, the top line is the publish subject and the second line and third lines are subscribers. The upward-pointing arrows indicate subscriptions and downward-pointing arrows represent emitted events.

In Korean version, you can refer this page

--

--

sinclair
sinclair

Written by sinclair

iOS developer, Processing practice

No responses yet