[RxSwift] RxSwift Basics

yeahsilver
2 min readAug 13, 2021

--

RxSwift

Reactive programming framwork for swift language to build the app.

RxCocoa

Framework that makes Cocoa API’s easier to use reactive techniques

Observable

Observing events (= Emit notifications of change)

Types of Events in Observable

  1. If new event would create to that Observable, next event will be sent to that Observer. It is called Emit
  2. If Observable has an error, error event will be sent to that Observer
  3. If Observable ends completely, completed event will be sent to that observer,

Observer

Subscribing to an Observable and noticing when that Observable action has changed.

Dealing with Observable’s events. It is called Subscribe

Disposable

It provides to help deal with memory management.

Completed and error, observer’s events, send at the end of the life cycle.

With executing completed and error, Swift automatically deallocate the resources, but recomended that calls disposable to deallocate the resources manually

Subject

It can act as both an observable and as an observer.

The subject received next events and also be subscribed to.

The subject receive next events, it turned around and emitted it to its subscriber.

Publish Subject

It is used when you simply want subscribers to be notified of new events from the point at which they subscribed.

PublisherSubject

It will receive information and then publish it to subscriber.

Also, it starts empty and only emits new elements to subscribers.

BehaviorSubject

It starts initial values and subscribe only an immediate value

Relay

It is the wrapper around subjects

PublishRelay

It is the wrapper around PublishSubject. It is only notified of values from the point after subscribing.

BehaviorRelay

It is the wrapper around BehaviorSubject. it can get the value using .value.

What is the difference btw Subject and Relay?

Subjects ends when .completed and .error events occur.

Relays continues working until it would disposed, without .completed and .error, so it is appropriate to use UI Events.

Reference

https://jinshine.github.io/2019/01/05/RxSwift/3.Subject%EB%9E%80/

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response