I am new to RxSwift programming. I am confused between the two while coding. Which one should be used to store datasource of table and how to decide that ?
import RxSwift. /// PublishRelay is a wrapper for `PublishSubject`. /// /// Unlike `PublishSubject` it can't terminate with error or completed. public final class PublishRelay<Element>: ObservableType {
RxSwift: Publish SubjectStarts empty and only emits new elements to subscribers. Useful when you want subscribers to be notified of new events from the point at which they subscribed until they either unsubscribe or termination ( . completed / . error ).
BehaviorSubject : Starts with an initial value and replays it or the latest element to new subscribers. ReplaySubject : Initialized with a buffer size and will maintain a buffer of elements up to that size and replay it to new subscribers.
Another important point that was alluded to by @RobMayoff in his comment. Neither a PublishSubject nor a PublishRelay stores state, so neither of them are a good idea to "store datasource of table".
Fortunately, you don't need to store the state yourself because the DataSource object that the items
operator creates internally stores it.
In other words, you don't need to use a Subject or Relay (of any sort) to feed a table view. Just use an Observable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With