|
| 1 | +# RxSwift to Combine Cheatsheet |
| 2 | +This is a Cheatsheet for [RxSwift](https://github.com/ReactiveX/RxSwift) developers interested in Apple's new [Combine](https://developer.apple.com/documentation/combine) framework. |
| 3 | + |
| 4 | +It's based on the following blog post: [https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b](https://medium.com/gett-engineering/rxswift-to-apples-combine-cheat-sheet-e9ce32b14c5b) |
| 5 | + |
| 6 | +## [Basics](Data/Basics.csv) |
| 7 | + |
| 8 | +| | RxSwift | Combine | |
| 9 | +|-----------------------|----------------------------------|--------------------------------------------| |
| 10 | +| Deployment Target | iOS 8.0+ | iOS 13.0+ | |
| 11 | +| Platforms supported | iOS, macOS, tvOS, watchOS, Linux | iOS, macOS, tvOS, watchOS, UIKit for Mac ¹ | |
| 12 | +| Spec | Reactive Extensions (ReactiveX) | Reactive Streams (+ adjustments) | |
| 13 | +| Framework Consumption | Third-party | First-party (built-in) | |
| 14 | +| Maintained by | Open-Source / Community | Apple | |
| 15 | +| UI Bindings | RxCocoa | SwiftUI ² | |
| 16 | + |
| 17 | + |
| 18 | +## [Core Components](Data/CoreComponents.csv) |
| 19 | + |
| 20 | +| RxSwift | Combine | Notes | |
| 21 | +|---------------------------|--------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 22 | +| Observable | Publisher | | |
| 23 | +| Driver | BindableObject (SwiftUI) | Both guarantee no failure, but Driver guarantees delivery on Main Thread. In Combine, SwiftUI recreates the entire view hierarachy on the Main Thread, instead. | |
| 24 | +| Single | Future | | |
| 25 | +| Disposable | Cancellable | There's no DisposeBag in Combine, AnyCancellable cancels on deinit. | |
| 26 | +| Observer | Subscriber | | |
| 27 | +| ConnectableObservableType | ConnectablePublisher | | |
| 28 | +| SubjectType | Subject | | |
| 29 | +| PublishSubject | PassthroughSubject | | |
| 30 | +| BehaviorSubject | CurrentValueSubject | This seems to be the type that holds @State under the hood | |
| 31 | +| SchedulerType | Scheduler | | |
| 32 | + |
| 33 | + |
| 34 | +## [Operators](Data/Operators.csv) |
| 35 | + |
| 36 | +| RxSwift | Combine | Notes | |
| 37 | +|-------------------------------|---------------------------------------|----------------------------------------------------------------------------------------------------------| |
| 38 | +| asObservable() | eraseToAnyPublisher() | | |
| 39 | +| asObserver() | eraseToAnySubject() | | |
| 40 | +| bind(to:) | `assign(to:on:)` | Assign uses a KeyPath which is really nice and useful. RxSwift needs a Binder / ObserverType to bind to. | |
| 41 | +| buffer | buffer | | |
| 42 | +| catchError | catch | | |
| 43 | +| catchErrorJustReturn | catch + just | | |
| 44 | +| combineLatest | combineLatest, tryCombineLatest | | |
| 45 | +| compactMap | compactMap, tryCompactMap | | |
| 46 | +| concat | append, prepend | | |
| 47 | +| debounce | debounce | | |
| 48 | +| debug | print | | |
| 49 | +| delay | delay | | |
| 50 | +| distinctUntilChanged | removeDuplicates, tryRemoveDuplicates | | |
| 51 | +| do | handleEvents | | |
| 52 | +| enumerated + skipWhile + take | output(at:), output(in:) | | |
| 53 | +| filter | filter, tryFilter | | |
| 54 | +| first | first, tryFirst | | |
| 55 | +| flatMap | flatMap | | |
| 56 | +| flatMapLatest | switchToLatest | | |
| 57 | +| ifEmpty(switchTo:) | replaceEmpty(with:) | | |
| 58 | +| ignoreElements() | ignoreOutput() | | |
| 59 | +| map | map, tryMap | | |
| 60 | +| merge | merge, tryMerge | | |
| 61 | +| multicast | multicast | | |
| 62 | +| observeOn | receive(on:) | | |
| 63 | +| reduce | reduce, tryReduce | | |
| 64 | +| retry, retry(3) | retry, retry(3) | | |
| 65 | +| scan | scan, tryScan | | |
| 66 | +| share | share | There doesn't seem to be a share(replay: 1) in Combine, yet | |
| 67 | +| skip(3) | dropFirst(3) | | |
| 68 | +| skipUntil | drop(untilOutputFrom:) | | |
| 69 | +| skipWhile | drop(while:), tryDrop(while:) | | |
| 70 | +| subscribe | sink | | |
| 71 | +| subscribeOn | subscribe(on:) | RxSwift uses Schedulers Combine uses RunLoop, DispatchQueue, and OperationQueue. | |
| 72 | +| take(3).toArray() | collect(3) | | |
| 73 | +| takeLast | last | | |
| 74 | +| throttle | throttle | | |
| 75 | +| timeout | timeout | | |
| 76 | +| toArray() | collect() | | |
| 77 | +| zip | zip | | |
| 78 | + |
| 79 | + |
| 80 | +# Contributing |
| 81 | +Add any data/operators to the appropriate CSV files in the **Data** folder, run `genreadme.rb` and commit the changes. Then, submit a Pull Request |
0 commit comments