Skip to content

Commit 508bf46

Browse files
joeblaufreak4pc
authored andcommitted
RxSwift to Combine Cheatsheet - Markdown & CSV
0 parents  commit 508bf46

File tree

8 files changed

+203
-0
lines changed

8 files changed

+203
-0
lines changed

Data/Basics.csv

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
,RxSwift,Combine
2+
Deployment Target,iOS 8.0+,iOS 13.0+
3+
Platforms supported,"iOS, macOS, tvOS, watchOS, Linux","iOS, macOS, tvOS, watchOS, UIKit for Mac ¹"
4+
Spec,Reactive Extensions (ReactiveX),Reactive Streams (+ adjustments)
5+
Framework Consumption,Third-party,First-party (built-in)
6+
Maintained by,Open-Source / Community,Apple
7+
UI Bindings,RxCocoa,SwiftUI ²

Data/CoreComponents.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
RxSwift,Combine,Notes
2+
Observable,Publisher,
3+
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."
4+
Single,Future,
5+
Disposable,Cancellable,"There's no DisposeBag in Combine, AnyCancellable cancels on deinit."
6+
Observer,Subscriber,
7+
ConnectableObservableType,ConnectablePublisher,
8+
SubjectType,Subject,
9+
PublishSubject,PassthroughSubject,
10+
BehaviorSubject,CurrentValueSubject,"This seems to be the type that holds @State under the hood"
11+
SchedulerType,Scheduler,

Data/Operators.csv

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
RxSwift,Combine,Notes
2+
asObservable(),eraseToAnyPublisher(),
3+
asObserver(),eraseToAnySubject(),
4+
bind(to:),`assign(to:on:)`,Assign uses a KeyPath which is really nice and useful. RxSwift needs a Binder / ObserverType to bind to.
5+
buffer,buffer,
6+
catchError,catch,
7+
catchErrorJustReturn,catch + just,
8+
combineLatest,"combineLatest, tryCombineLatest",
9+
compactMap,"compactMap, tryCompactMap",
10+
concat,"append, prepend",
11+
debounce,debounce,
12+
debug,print,
13+
delay,delay,
14+
distinctUntilChanged,"removeDuplicates, tryRemoveDuplicates",
15+
do,handleEvents,
16+
enumerated + skipWhile + take,"output(at:), output(in:)",
17+
filter,"filter, tryFilter",
18+
first,"first, tryFirst",
19+
flatMap,flatMap,
20+
flatMapLatest,switchToLatest,
21+
ifEmpty(switchTo:),replaceEmpty(with:),
22+
ignoreElements(),ignoreOutput(),
23+
map,"map, tryMap",
24+
merge,"merge, tryMerge",
25+
multicast,multicast,
26+
observeOn,receive(on:),
27+
reduce,"reduce, tryReduce",
28+
"retry, retry(3)","retry, retry(3)",
29+
scan,"scan, tryScan",
30+
share,share,"There doesn't seem to be a share(replay: 1) in Combine, yet"
31+
skip(3),dropFirst(3),
32+
skipUntil,drop(untilOutputFrom:),
33+
skipWhile,"drop(while:), tryDrop(while:)",
34+
subscribe,sink,
35+
subscribeOn,subscribe(on:),"RxSwift uses Schedulers Combine uses RunLoop, DispatchQueue, and OperationQueue."
36+
take(3).toArray(),collect(3),
37+
takeLast,last,
38+
throttle,throttle,
39+
timeout,timeout,
40+
toArray(),collect(),
41+
zip,zip,

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
source 'https://rubygems.org' do
2+
gem 'csv2md'
3+
end

Gemfile.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
csv2md (1.1.3)
5+
6+
PLATFORMS
7+
ruby
8+
9+
DEPENDENCIES
10+
csv2md!
11+
12+
BUNDLED WITH
13+
2.0.1

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Joe Blau
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

genreadme.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env ruby
2+
3+
system("csv2md > /dev/null 2>&1")
4+
error("csv2md is not intalled, Please run `bundle install` first") unless $?.exitstatus == 0
5+
6+
docs = {
7+
"Basics.csv" => "Basics",
8+
"CoreComponents.csv" => "Core Components",
9+
"Operators.csv" => "Operators"
10+
}
11+
12+
output = "# RxSwift to Combine Cheatsheet\n" +
13+
"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.\n\n" +
14+
"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)\n\n"
15+
16+
docs.each { |file, title|
17+
output += "## [#{title}](Data/#{file})\n\n"
18+
output += `csv2md Data/#{file}`
19+
output += "\n\n"
20+
}
21+
22+
output += "# Contributing\n"
23+
output += "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"
24+
25+
26+
File.write('README.md', output)

0 commit comments

Comments
 (0)