Latest 1.1.0
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, tvos 9.0
Dependencies ReSwift


Build Status Code coverage status CocoaPods Compatible Platform support License MIT Reviewed by Hound

Supported Swift Versions: Swift 4.1, Swift 4.2

When ReSwift is a Redux-like implementation of the unidirectional data flow architecture in Swift, ReSwift-Thunk is like redux-thunk.

Why Use ReSwift-Thunk?


// First, you create the middleware, which needs to know the type of your `State`.
let thunksMiddleware: Middleware<MyState> = createThunksMiddleware()

// Note that it can perfectly live with other middleware in the chain.
let store = Store<MyState>(reducer: reducer, state: nil, middleware: [thunksMiddleware])

// A thunk represents an action that can perform side effects, access the current state of the store, and dispatch new actions, as if it were a ReSwift middleware.
let thunk = Thunk<MyState> { dispatch, getState in 
    if getState!.loading {
    api.getSomething() { something in
        if something != nil {
        } else {

// A thunk can also be a function if you want to pass on parameters
func thunkWithParams(_ identifier: Int) -> Thunk<MyState> {
    return Thunk<MyState> { dispatch, getState in
        guard let state = getState() else { return }

        if state.loading {

        api.getSomethingWithId(identifier) { something in
            if something != nil {
            } else {

// As the thunk type conforms to the `Action` protocol, you can dispatch it as usual, without having to implement an overload of the `dispatch` function inside the ReSwift library.

// You can do the same with the Thunk that requires parameters, like so

// Note that these actions won't reach the reducers, instead, the thunks middleware will catch it and execute its body, producing the desired side effects.


ReSwift-Thunk requires the ReSwift base module.


You can install ReSwift-Thunk via CocoaPods by adding it to your Podfile:


source ''
platform :ios, '8.0'

pod 'ReSwift'
pod 'ReSwiftThunk'

And run pod install.


You can install ReSwift-Thunk via Carthage by adding the following line to your Cartfile:

github "ReSwift/ReSwift-Thunk"

Swift Package Manager

You can install ReSwift-Thunk via Swift Package Manager by adding the following line to your Package.swift:

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "", majorVersion: XYZ)

Checking out Source Code

After checking out the project run pod install to get the latest supported version of SwiftLint, which we use to ensure a consistent style in the codebase.

Example Projects

  • ReduxMovieDB: A simple App that queries the API to display the latest movies. Allows searching and viewing details. Relevant file.


You can find all the details on how to get started in the Contributing Guide.



ReSwift-Thunk Copyright (c) 2018 ReSwift Contributors. Distributed under the MIT License (MIT). See

Latest podspec

    "name": "ReSwiftThunk",
    "version": "1.1.0",
    "summary": "Thunk middleware for ReSwift.",
    "description": "ReSwift-Thunk allows you to write action creators that return a function instead of an action. Instead of dispatching an `Action` directly, you can dispatch a `Thunk` that creates an action at a later time, for example after a network request finishes.",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": ""
    "authors": "ReSwift",
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    "module_name": "ReSwiftThunk",
    "swift_version": "4.2",
    "source": {
        "git": "",
        "tag": "1.1.0"
    "source_files": "ReSwift-Thunk",
    "dependencies": {
        "ReSwift": [
            "~> 4.0"

Pin It on Pinterest

Share This