Swiftpack.co - Package - NoTests/RxFeedback.swift


Travis CI platforms pod Carthage compatible Swift Package Manager compatible

20min video pitch

The simplest architecture for RxSwift

    typealias Feedback<State, Mutation> = (Observable<State>) -> Observable<Mutation>

    public static func system<State, Mutation>(
            initialState: State,
            reduce: @escaping (State, Mutation) -> State,
            feedback: Feedback<State, Mutation>...
        ) -> Observable<State>


  • Straightforward

    • if it's state -> State
    • if it's a way to modify state -> Mutation/Command
    • it it's an effect -> encode it into part of state and then design a feedback loop
  • Declarative

    • System behavior is first declaratively specified and effects begin after subscribe is called => Compile time proof there are no "unhandled states"
  • Debugging is easier

    • A lot of logic is just normal pure function that can be debugged using Xcode debugger, or just printing the commands.
  • Can be applied on any level

    • Entire system
    • application (state is stored inside a database, CoreData, Firebase, Realm)
    • view controller (state is stored inside system operator)
    • inside feedback loop (another system operator inside feedback loop)
  • Works awesome with dependency injection

  • Testing

    • Reducer is a pure function, just call it and assert results
    • In case effects are being tested -> TestScheduler
  • Can model circular dependencies

  • Completely separates business logic from effects (Rx).

    • Business logic can be transpiled between platforms (ShiftJS, C++, J2ObjC)


Simple UI Feedback loop

    initialState: 0,
    reduce: { (state: State, mutation: Mutation) -> State in
            switch mutation {
            case .increment:
                return state + 1
            case .decrement:
                return state - 1
    scheduler: MainScheduler.instance,
        // UI is user feedback
        bind { state in
                state.map(String.init).bind(to: label.rx.text)
            ], [
                plus.rx.tap.map { Mutation.increment },
                minus.rx.tap.map { Mutation.decrement }

Play Catch

Simple automatic feedback loop.

    initialState: State.humanHasIt,
    reduce: { (state: State, mutation: Mutation) -> State in
        switch mutation {
            case .throwToMachine:
                return .machineHasIt
            case .throwToHuman:
                return .humanHasIt
    scheduler: MainScheduler.instance,
        // UI is human feedback
        // NoUI, machine feedback
        react(request: { $0.machinePitching }, effects: { () -> Observable<Mutation> in
            return Observable<Int>
                .timer(1.0, scheduler: MainScheduler.instance)
                .map { _ in Mutation.throwToHuman }


    initialState: State.empty,
    reduce: State.reduce,
        // UI, user feedback
        // NoUI, automatic feedback
        react(request: { $0.loadNextPage }, effects: { resource in
            return URLSession.shared.loadRepositories(resource: resource)
                .asDriver(onErrorJustReturn: .failure(.offline))

Run RxFeedback.xcodeproj > Example to find out more.



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

To integrate RxFeedback into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'RxFeedback', '~> 1.0'

Then, run the following command:

$ pod install


Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate RxFeedback into your Xcode project using Carthage, specify it in your Cartfile:

github "NoTests/RxFeedback" ~> 1.0

Run carthage update to build the framework and drag the built RxFeedback.framework into your Xcode project. As RxFeedback depends on RxSwift and RxCocoa you need to drag the RxSwift.framework and RxCocoa.framework into your Xcode project as well.

Swift Package Manager

The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.

Once you have your Swift package set up, adding RxFeedback as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/NoTests/RxFeedback.swift.git", majorVersion: 1)

Difference from other architectures

  • Elm - pretty close, feedback loops for effects instead of Cmd, which effects to perform are encoded into state and queried by feedback loops
  • Redux - kind of like this, but feedback loops instead of middleware
  • Redux-Observable - observables observe state vs. being inside middleware between view and state
  • Cycle.js - no simple explanation :), ask @andrestaltz
  • MVVM - separates state from effects and doesn't require a view


Stars: 684
Help us keep the lights on


Used By

Total: 0


1.1.1 - Nov 13, 2018

  • Fixes problem building with Carthage. #41

1.1.0 - Sep 21, 2018

  • Xcode 10 compatbility
  • Renames Event to Mutation.

1.0.3 - Jun 13, 2018

  • Fixes problem with feedback loop termination.

1.0.2 - Dec 6, 2017

  • Fixes duplicated plist inclusion.

1.0.1 - Nov 9, 2017

  • Fixes leak in Hashable overload of react feedback loop.
  • Shares final guard against reentrancy (if feedback loops have implementation issue and are synchronous) between all feedback loops.