Swiftpack.co - adamaszhu/iCombine as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by adamaszhu.
adamaszhu/iCombine 0.4.8
Support combine syntax on iOS 9 and above
⭐️ 2
πŸ•“ 2 years ago
.package(url: "https://github.com/adamaszhu/iCombine.git", from: "0.4.8")

iCombine



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.

Install

Cocoapods

Include follow pod line in the Podfile

pod iCombine

Swift package manager

Add a Package Dependency using the current Github URL

How to use

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)

Documentation

Combine Interfaces

Snippet

To bridge iCombine with ReactiveSwift, please use this snippet iCombine+Convertable.swift

For ReactiveSwift 5.x please use this snippet iCombine+ReactiveSwift5.swift

WIP

Publisher

  • β˜‘ receive<S>(subscriber: S)
  • β˜‘ eraseToAnyPublisher

AnyPublisher

  • β˜‘ init<P>(_ publisher: P)

Just

  • β˜‘ init

HandleEvents

  • β˜‘ init
  • β˜‘ handleEvents

Map

  • β˜‘ map
  • β˜‘ tryMap

MapError

  • β˜‘ init(upstream: Upstream, transform: @escaping (Upstream.Failure) -> Failure)
  • β˜‘ init(upstream: Upstream, _ map: @escaping (Upstream.Failure) -> Failure)
  • β˜‘ mapError

Publishers

TryMap

  • β˜‘ map
  • β˜‘ tryMap

Map

  • β˜‘ init(upstream: Upstream, transform: @escaping (Upstream.Output) -> Output)
  • β˜‘ map
  • β˜‘ tryMap

Sequence

  • β˜‘ 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

Subject

  • β˜‘ behaviourSubject
  • ☐ send(_ value: Self.Output)
  • ☐ send(completion: Subscribers.Completion<Self.Failure>)
  • ☐ send(subscription: Subscription)

CurrentValueSubject

  • β˜‘ init
  • ☐ send(subscription: Subscription)
  • ☐ send(_ input: Output)
  • ☐ send(completion: Subscribers.Completion)

Subscribers

Completion

  • β˜‘ finished
  • β˜‘ failure(Failure)

Subscriber

  • ☐ receive(subscription: Subscription)
  • ☐ receive(_ input: Self.Input)
  • ☐ receive(completion: Subscribers.Completion<Self.Failure>)

Sink

  • β˜‘ init
  • ☐ disposable
  • ☐ receiveValue
  • ☐ receiveCompletion
  • ☐ receive(subscription: Subscription)
  • ☐ receive(_ value: Input) -> Subscribers.Demand
  • ☐ receive(completion: Subscribers.Completion)
  • ☐ cancel

Cancellable

  • β˜‘ cancel

Subscription

  • β˜‘ request

And more ...

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.

GitHub

link
Stars: 2
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics