Latest 0.2.1
License MIT
Platforms ios 8.0
Dependencies RxSwift

CI Status


What is Flux?

Flux is the application architecture that Facebook uses for building client-side web applications.

Core of Flux

  • Unidirectional flow
  • View – Store – Action – Dispatcher


Minimal library for swift that according to flux concept.


Swiflux is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Swiflux"


  • RxSwift 3.x (or higher)
  • Swift 3.x (or higher)


1. Import library

import Swiflux

2. Write Store class

i. extends StoreBase

class UserStore: StoreBase

ii. Override some (optional)

override func buildDefaultState() {
override func bindEvents() {

iii. Subscribe Action and change state

  • state : a data that store has. changing of state will be broadcast to views who subscribe.

    class UserStore: StoreBase {
    override func buildDefaultState() {
        //default state value
        setState(for: "greeting", state: "")
    override func bindEvents() {
        //subscribe action event "app:greeting"
        Dispatcher.shared().on("app:greeting") { props in
            guard let props = props else { return }
            let firstName = props["firstName"] as! String
            let lastName = props["lastName"] as! String
            self.buildGreetMessage(first: firstName, last: lastName)
    func buildGreetMessage(first: String, last: String) {
        var greet = "Hi~ there!"
        if first.isEmpty && !last.isEmpty {
            greet = "Hello, (last)."
        } else if !first.isEmpty && last.isEmpty {
            greet = "Hi, (first)."
        } else if !first.isEmpty && !last.isEmpty {
            greet = "Hello, (first) (last)!"
        //change state, and notify to View
        self.setState(for: "greeting", state: greet)

3. Bind Store with View

let userStore = UserStore()

//bind state data via UserStore
userStore.on("greeting") { greet in
    let greet = greet as! String
    self.greetingLabel.text = greet

4. Send Action events to Dispatcher

//Send Action Event
Dispatcher.shared().send("app:greeting", props: [
    "firstName": firstName as AnyObject,
    "lastName": lastName as AnyObject

Refer Example source code


Ryan Song<[email protected]>


Swiflux is available under the MIT license. See the LICENSE file for more info.

Latest podspec

    "name": "Swiflux",
    "version": "0.2.1",
    "summary": "Minimal flux library for swift",
    "description": "Minimal flux library for swift",
    "homepage": "",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    "authors": {
        "iamchiwon": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.2.1"
    "platforms": {
        "ios": "8.0"
    "source_files": "Swiflux/Classes/**/*",
    "dependencies": {
        "RxSwift": []
    "pushed_with_swift_version": "3.0"

Pin It on Pinterest

Share This