Swiftpack.co -  velos/Combiner as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A Combine-based version of ReactorKit
.package(url: "https://github.com/velos/Combiner.git", from: "0.0.4")


A 1:1 port of ReactorKit using Combine instead of RxSwift. Also includes some basic extensions for working with SwiftUI.

Basic Architecture

Combiners are state machines which take in Actions and produce States which can be bound to UI elements in UIViewControllers or SwiftUI views.

This allows an implementation of unidirectional architecture, where inputs from the UI go into the Combiner to produce outputs of state changes.

Combiner data flow


Using a Combiner first requires creating a subclass of Combiner. The subclass must create an associated type for State which is the view state represented by the Combiner. It also must create an Action associated type, usually declared as an enum, which defines all the inputs the Combiner will get from the view. Next, the internal Mutation is associated as well, again usually as an enum. The Mutation type defines the operations that can be made to the State and very often, but not necessarily, is 1:1 with properties of the State.

After these types are declared, the following functions are required to be implemented:

  • func mutate(action: Action) -> AnyPublisher<Mutation, Never>
    • Implements taking an incoming action and producing a publisher which produces zero or more mutations that are applied serially to the outgoing view state.
  • func reduce(state: State, mutation: Mutation) -> State
    • Takes the mutations that are being produced as a result of the outputs to the publisher from the mutate function and applies them to the current state to produce a new state.

Now the state property is available on the combiner to observe and bind to changes to the view.

More Information

For more information, please check out the ReactorKit repo since almost all implementation details apply to this port.


Stars: 0
Last commit: 4 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

0.0.4: Main Thread Fix
4 weeks ago

This release improves thread handling when updating the current state which helps with SwiftUI data flow.

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