Swiftpack.co -  sergejs/StateMachine as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
sergejs/StateMachine
Swift implamentation of Finite State Machine using Combine & Generics
.package(url: "https://github.com/sergejs/StateMachine.git", from: "1.2.2")

StateMachine

Package containing easy implamentation of Finite State Machine using Combine

To start using, all you need is to defeine enums with States and Events, and define Transitions.

TODO:

[ ] Improved logging control

Example usage

enum TestEvents: EventProtocol {
  case event1, event2
}

enum TestStates: StateProtocol {
  case initial, step1, step2, step1Alt, finish
}

let stateMachine = StateMachine<TestEvents, TestStates>(with: .initial)
let transition = StateMachineTransition<TestEvents, TestStates>(event: .event1, from: .initial, to: .finish)
try? stateMachine.append(transition: transition)
stateMachine.transitionQueue.waitUntilAllOperationsAreFinished()
XCTAssertEqual(stateMachine.state.value, .initial)

stateMachine.event.send(.event1)
stateMachine.transitionQueue.waitUntilAllOperationsAreFinished()
XCTAssertEqual(stateMachine.state.value, .finish)

Check tests for more usage exmples

GitHub

link
Stars: 3
Last commit: 6 days 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.

Dependencies

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