- Can act as both an
Observableand as an
.onNext(_:)puts a new element onto the subject.
- Need subscribers for events to happen.
- Every subject type, once terminated will re-emit its stop event to future subscribers.
4 different types of Subjects:
- PublishSubject: Starts empty and only emits new elements to subscribers.
- BehaviorSubject: Starts with an initial value and replays it or the latest element to new subscribers.
- ReplaySubject: Initialised with a buffer size and will maintain a buffer of elements up to that size and replay it to new subscribers.
BehaviorSubject. Preservers its current value as state and replays only the latest/initial value to new subscribers.
< All Posts