Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coderyi/statemachineswift
StateMachineSwift, state machine library for Swift, supports an arbitrary number of States and Events.
https://github.com/coderyi/statemachineswift
ios state-machine statemachine swift
Last synced: 2 months ago
JSON representation
StateMachineSwift, state machine library for Swift, supports an arbitrary number of States and Events.
- Host: GitHub
- URL: https://github.com/coderyi/statemachineswift
- Owner: coderyi
- License: mit
- Created: 2020-12-03T01:37:30.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-20T14:39:17.000Z (almost 3 years ago)
- Last Synced: 2024-09-23T22:17:46.891Z (4 months ago)
- Topics: ios, state-machine, statemachine, swift
- Language: Swift
- Homepage:
- Size: 25.4 KB
- Stars: 41
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
StateMachineSwift, supports an arbitrary number of States and Events.
### CocoaPods
```
pod 'StateMachineSwift'
```### Features
* Supports an arbitrary number of States and Events.
* States and Events support a thorough set of callbacks for responding to state transitions.
* Transitions support the inclusion of arbitrary user data via a userInfo dictionary, making it easy to broadcast metadata across callbacks.
* Lightweight.### Example
```
let orderStateMachine: SMStateMachine = SMStateMachine()let normal: SMState = SMState("normal")
let purchase: SMState = SMState("purchase")
let cancel: SMState = SMState("cancel")orderStateMachine.addStates(arrayOfStates: [normal, purchase, cancel])
orderStateMachine.initialState = normallet confirmOrder: SMEvent = SMEvent("confirmOrder", sourceStates: [normal], destinationState: purchase)
let cancelOrder: SMEvent = SMEvent("cancelOrder", sourceStates: [purchase, normal], destinationState: cancel)orderStateMachine.addEvents(arrayOfEvents: [confirmOrder, cancelOrder])
orderStateMachine.activate()
orderStateMachine.isInState("normal")let userInfo = ["hello": "world"]
orderStateMachine.fireEvent(eventName: "confirmOrder", userInfo: userInfo)
orderStateMachine.fireEvent(eventName: "cancelOrder", userInfo: userInfo)
```
## License
Released under [MIT License](LICENSE).