Latest 3.0.3
Homepage https://github.com/vknabel/Finite
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Authors

[CocoaPods]()
[CocoaPods]()
[Install]()
[License]()

Finite is a simple, pure Swift finite state machine. Only exlicitly allowed transitions between states are allowed, otherwise an error will be thrown.

Finite Swift
2.0.0 2.2 and 3.0 Beta
3.x.x 3.0 and 4.0

Installation

EasyInject is a Swift only project and supports Swift Package Manager, Carthage and CocoaPods.

Swift Package Manager

import PackageDescription

let package = Package(
    name: "YourPackage",
    dependencies: [
        .Package(url: "https://github.com/vknabel/EasyInject.git", majorVersion: 3)
    ]
)

Carthage

github "vknabel/EasyInject"

CocoaPods

source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

pod 'EasyInject'

Introduction

It operates on a given type, where each value represents an internal state of the machine. A StateMachine is defined by providing all allowed state transitions.

enum Test: Int {
    case saving, Fetching, Deleting
    case Ready, Fail
}

var machine = StateMachine<Test>(initial: .ready) { c in
    c.allow(from: [.saving, .fetching, .deleting], to: [.ready, .fail])
    c.allow(from: .ready, to: [.saving, .fetching, .deleting])
}

It is possible to provide callbacks, that will be called once certain transitions will happen.

machine.onTransitions(from: .ready) {
    println("From Ready: show activity indicator")
}
machine.onTransitions(to: .ready) {
    println("To Ready: hide activity indicator")
}
machine.onTransitions(to: .saving) {
    println("To: save")
}

Once the StateMachine has been set up, you may trigger all transitions you have declared above.

try machine.transition(to: .saving) {
    println("Triggered: save")
}

// this will throw an error
try machine.transition(to: .fetching)

Author

Valentin Knabel, [email protected]

License

Finite is available under the MIT license.

Latest podspec

{
    "name": "Finite",
    "version": "3.0.3",
    "summary": "A simple state machine written in Swift.",
    "description": "Finite is a simple, pure Swift finite state machine.",
    "social_media_url": "https://twitter.com/vknabel",
    "homepage": "https://github.com/vknabel/Finite",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Valentin Knabel": "[email protected]"
    },
    "source": {
        "git": "https://github.com/vknabel/Finite.git",
        "tag": "3.0.3"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source_files": "Sources/*.swift",
    "pushed_with_swift_version": "4.0"
}

Pin It on Pinterest

Share This