I wonder if there is an excellent document to show the difference between Combine and RxSwift?
It's good for me to quickly learn the Combine
because I already had good knowledge about RxSwift
Đức Bùi posted a good article detailing the surface level differences. In this answer, I'll cover some other differences I've discovered...
A Cancellable
and a Disposable
are much more different than the article suggests. The former is required to keep the subscription alive, while the latter is only needed if you want to explicitly kill the subscription. So Disposables can be ignored, but Cancellables never can.
The share(replay: x)
operator in Combine is equivalent to RxSwift's .share(replay: x, scope: .forever)
and there is no notion of a share .whileConnected
. This means that shared publishers can't be restarted like shared Observables can.
Other issues:
eraseToAnyPublisher()
operator provides some relief but
having to constantly use it is its own torture.As for benefits? I have only found one. Combine Subjects are thread safe whereas RxSwift Subjects are not. In RxSwift you rarely need Subjects anyway, in Combine you need them constantly.