|
| 1 | +# RxSwift to ReactiveSwift Cheatsheet |
| 2 | +This is a Cheatsheet for [RxSwift](https://github.com/ReactiveX/RxSwift) developers migrating to projects using [ReactiveSwift](https://github.com/ReactiveCocoa/ReactiveSwift). |
| 3 | + |
| 4 | +Inspired by the [RxSwift to Combine cheatsheet](https://github.com/CombineCommunity/rxswift-to-combine-cheatsheet) |
| 5 | + |
| 6 | +## Basics |
| 7 | + |
| 8 | +| | RxSwift | ReactiveSwift | |
| 9 | +|-----------------------|----------------------------------|--------------------------------------------| |
| 10 | +| Deployment Target | iOS 8.0+ | iOS 8.0+ |
| 11 | +| Platforms supported | iOS, macOS, tvOS, watchOS, Linux | iOS, macOS, tvOS, watchOS, Linux |
| 12 | +| Spec | Reactive Extensions (ReactiveX) | Originally ReactiveX, with significant divergence |
| 13 | +| Framework Consumption | Third-party | Third-party |
| 14 | +| Maintained by | Open-Source / Community | Open-Source / Community |
| 15 | +| UI Bindings | RxCocoa | ReactiveCocoa |
| 16 | + |
| 17 | + |
| 18 | +## Core Components |
| 19 | + |
| 20 | +| RxSwift | ReactiveSwift | Notes | |
| 21 | +|---------------------------|---------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 22 | +| AnyObserver | Signal.Observer | In practice, since there are no different Observer types, the AnyObserver concept is redundant in ReactiveSwift |
| 23 | +| BehaviorRelay | Property / MutableProperty | Since `MutableProperty` can never have errors, we don't need a Relay specific version. |
| 24 | +| BehaviorSubject | Property / MutableProperty | |
| 25 | +| Completable | Signal / SignalProducer | A `Signal` or `SignalProducer` where `Value == Never` can only complete or emit an error event |
| 26 | +| CompositeDisposable | CompositeDisposable | |
| 27 | +| ConnectableObservableType | ❌ | |
| 28 | +| Disposable | Disposable | In ReactiveSwift you rarely have to keep hold of Disposables or manage their lifetime manually, it's mostly automatic. |
| 29 | +| DisposeBag | CompositeDisposable | The concepte of a DisposeBag is not really needed in ReactiveSwift, see above. |
| 30 | +| Driver | ❌ | |
| 31 | +| Maybe | ❌ | Trivial to create using `take(first: 1)` |
| 32 | +| Observable | Signal / SignalProducer | Signal is a "hot" observable, and SignalProducer is a "cold" observable that will only emit values once a subscription is started |
| 33 | +| Observer | Signal.Observer | |
| 34 | +| PublishRelay | ❌ | Could be recreated easily in ReactiveSwift using the `flatMapError` operator on a Signal.pipe() |
| 35 | +| PublishSubject | Signal.pipe() | There is no Subject type, but `Signal.pipe()` returns a tuple of `(output: Signal, input: Signal.Observer)` which you use to both observe and send values |
| 36 | +| ReplaySubject | ❌ | Can be created using the `replayLazily(upTo:)` operator |
| 37 | +| ScheduledDisposable | ❌ | |
| 38 | +| SchedulerType | Scheduler | |
| 39 | +| SerialDisposable | SerialDisposable | |
| 40 | +| Signal | ❌ | Not to be confused with ReactiveSwift `Signal` which is completely different |
| 41 | +| Single | ❌ | Could easily be created as an initializer for `SignalProducer` |
| 42 | +| SubjectType | Signal.pipe() | There is no Subject type, but `Signal.pipe()` returns a tuple of `(output: Signal, input: Signal.Observer)` which you use to both observe and send values |
| 43 | +| TestScheduler | TestScheduler | |
| 44 | + |
| 45 | + |
| 46 | +## Operators |
| 47 | + |
| 48 | +| RxSwift | Combine | Notes | |
| 49 | +|-----------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------| |
| 50 | +| amb() | flatten(.race) | |
| 51 | +| asObservable() | ❌ | Not required in ReactiveSwift, although `Property.producer` and `Property.signal` are similar |
| 52 | +| asObserver() | ❌ | |
| 53 | +| bind(to:) | <~ operator (BindingTargets) | |
| 54 | +| buffer | ❌ | (it used to exist, but was removed) |
| 55 | +| catchError | flatMapError | |
| 56 | +| catchErrorJustReturn | ❌ | Easy to create as `flatMapError { _ in SignalProducer<Value, Never> (value: value) }` |
| 57 | +| combineLatest | combineLatest | |
| 58 | +| compactMap | compactMap | |
| 59 | +| concat | concat / prefix | |
| 60 | +| concatMap | ❌ | |
| 61 | +| create | SignalProducer.init { } | |
| 62 | +| debounce | debounce | |
| 63 | +| debug | logEvents | |
| 64 | +| deferred | ❌ | Trivial to create |
| 65 | +| delay | delay | |
| 66 | +| delaySubscription | ❌ | |
| 67 | +| dematerialize | dematerialize | |
| 68 | +| distinctUntilChanged | skipRepeats | |
| 69 | +| do | on | |
| 70 | +| elementAt | ❌ | |
| 71 | +| empty | SignalProducer.empty | |
| 72 | +| enumerated | ❌ | |
| 73 | +| error | SignalProducer.init(error:) | |
| 74 | +| filter | filter | |
| 75 | +| first | take(first:) | See also `take(last:)` |
| 76 | +| flatMap | flatMap(.merge) | |
| 77 | +| flatMapFirst | flatMap(.throttle) | |
| 78 | +| flatMapLatest | flatMap(.latest) | |
| 79 | +| from(optional:) | ❌ | Easy to create using `.init(.value: Value?).skipNil()` |
| 80 | +| groupBy | ❌ | |
| 81 | +| ifEmpty(default:) | ❌ | |
| 82 | +| ifEmpty(switchTo:) | ❌ | |
| 83 | +| ignoreElements | ❌ | Easy to create |
| 84 | +| interval | ❌ | |
| 85 | +| just | SignalProducer.init(value:) | |
| 86 | +| map | map | |
| 87 | +| materialize | materialize | |
| 88 | +| merge | merge | |
| 89 | +| merge(maxConcurrent:) | ❌ | |
| 90 | +| multicast | replayLazily(upTo:) | |
| 91 | +| never | SignalProducer.never | |
| 92 | +| observeOn | observe(on:) | |
| 93 | +| of | SignalProducer.init(_ values:) | |
| 94 | +| publish | ❌ | |
| 95 | +| range | ❌ | |
| 96 | +| reduce | reduce | |
| 97 | +| refCount | ❌ | Not meaningful in ReactiveSwift |
| 98 | +| repeatElement | repeat | |
| 99 | +| retry, retry(3) | retry(upTo:) | |
| 100 | +| retryWhen | ❌ | |
| 101 | +| sample | sample(on:), sample(with:) | |
| 102 | +| scan | scan | |
| 103 | +| share | replayLazily(upTo:) | |
| 104 | +| skip | skip(first:) | |
| 105 | +| skipUntil | skip(until:) | |
| 106 | +| skipWhile | skip(while:) | |
| 107 | +| startWith | prefix | |
| 108 | +| subscribe | startWithValues / observeValues | |
| 109 | +| subscribeOn | start(on:) / observe(on:) | |
| 110 | +| takeLast | take(last:) | |
| 111 | +| takeUntil | take(until:) | |
| 112 | +| throttle | throttle | |
| 113 | +| timeout | timeout | |
| 114 | +| timer | SignalProducer.timer | |
| 115 | +| toArray | collect | |
| 116 | +| window | ❌ | |
| 117 | +| withLatestFrom | combineLatest | |
| 118 | +| zip | zip | |
0 commit comments