iCombine gives developers the ability to use Combine syntax on iOS below 13. In other word, iCombine makes Combine available on iOS 12 to 8. The way that we do this is to create a wrapper around RxSwift to offer Combine syntax.
Q: What's the benefit of iCombine?
A: Developers can write Combine code now for their applications to support all the iOS from 15 to 8 and when the time is right, they can do a global find and replace to replace all the import iCombine
by import Combine
and everything will just work.
Include follow pod line in the Podfile
pod iCombine
Add a Package Dependency
using the current Github URL
import iCombine
let subscriber = Subscribers.Sink<Int, Never>(
receiveCompletion: { completion in
print(completion)
}) { value in
print(value)
}
Publishers
.Sequence<[Int], Never>(sequence: [1, 2, 3, 4])
.receive(subscriber: subscriber)
To bridge iCombine with ReactiveSwift, please use this snippet iCombine+Convertable.swift
For ReactiveSwift 5.x please use this snippet iCombine+ReactiveSwift5.swift
β init
β map
β append(_ publisher: Publishers.Sequence<Elements, Failure>)
β append<S>(_ elements: S)
β append(_ elements: Publishers.Sequence<Elements, Failure>.Output...)
β prepend(_ publisher: Publishers.Sequence<Elements, Failure>)
β prepend<S>(_ elements: S)
β prepend(_ elements: Publishers.Sequence<Elements, Failure>.Output...)
β allSatisfy
β tryAllSatisfy
β collect
β compactMap
β contains
β tryContains
β drop
β dropFirst
β filter
β ignoreOutput
β prefix(_ maxLength: Int)
β prefix(while predicate: (Elements.Element) -> Bool)
β reduce
β tryReduce
β replaceNil
β scan
β setFailureType
RxSwift | Combine | Notes |
---|---|---|
ConnectableObservableType | ConnectablePublisher | |
Driver | BindableObject(SwiftUI) | Both guarantee no failure, but Driver guarantees delivery on Main Thread. In Combine, SwiftUI recreates the entire view hierarchy on the Main Thread, instead. |
Single | Future | They're only similar in the sense of single emission, but Future shares resources and executes immediately (very strange behavior) |
bind(to:) | assign(to: on:) | Assign uses a KeyPath which is really nice and useful. RxSwift needs a Binder / ObserverType to bind. |
buffer | buffer | |
combineLatest | combineLatest, tryCombineLatest | |
compactMap | compactMap, tryCompactMap | |
debounce | debounce | |
deferred | Publishers.Deferred | |
delay | delay | |
elementAt | output(at:) | |
flatMapLatest | switchToLatest | |
ignoreElements | ignoreOutput | |
merge | merge, tryMerge | |
merge(maxConcurrent:) | flatMap(maxPublishers:) | |
multicast | multicast | |
publish | makeConnectable | |
reduce | reduce, tryReduce | |
refCount | autoconnect | |
scan | scan, tryScan | |
share | share | Thereβs no replay or scope in Combine. Could be βfakedβ with multicast. |
startWith | prepend | |
subscribeOn | subscribe(on:) | RxSwift uses Schedulers. Combine uses RunLoop, DispatchQueue, and OperationQueue. |
takeUntil | prefix(untilOutputFrom:) | |
throttle | throttle | |
timeout | timeout | |
timer | Timer.publish | |
toArray() | collect() | |
window | collect(Publishers.TimeGroupingStrategy) | Combine has a TimeGroupingStrategy.byTimeOrCount that could be used as a window. |
link |
Stars: 2 |
Last commit: 2 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics