
RxSwift — Reactive Thinking (Part 3)
Distinguishing quality or characteristic.
We have gone through the Observable which is a regular observable. Today, we are going to know about traits which are a more clear, readable, intuitive and focused type of Observable.
There are three kinds of traits in RxSwift.
- Single
Single is a very dedicated observable which emit the .success or .error event.
It’s useful for one time tasks & expected to return either success with data or failure. In the applications, we need data/records from the local database, network call to fetch data or reading files.
As a developer, we are expecting success with result data or error for some reason.
- Completable
As the name says, it emits .completed or .error event. It’s useful for a one time tasks & expected nothing in return just failure or is completed. In the applications, we need to update the local database, upload the data/image to the server, delete the data/local files.
As a developer, we just need to know is task completed no data/information is expected in return unless there is an error with some reason.
- Maybe
It ’s maybe a combination of Single & Completable. It’s emit all the events which regular observable returns like .success(value), .error and .completed.
The best advice I ever got was that knowledge is power and to keep reading. — David Bailey