Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
State machine creation framework written in Swift inspired by GKStateMachine from Apple GameplayKit
License
NotificationsYou must be signed in to change notification settings
alexruperez/StateMachine
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Swift library to createFinite-state machines inspired byGKStateMachine from AppleGameplayKit framework.
Test StateMachine working live!
- Define States and Their Behavior.
- Create and Drive a State Machine.
- Subscribe/unsubscribe to State changes.
- UIApplication and UIApplicationDelegate extensions with application life cycle State Machine embedded.
- StatefulViewController subclass with UIViewController life cycle State Machine embedded.
StateMachine is available throughCocoaPods. To installit, simply add the following line to your Podfile:
pod'ArchitStateMachine'
Or you can install it withCarthage:
github "alexruperez/StateMachine"Or install it withSwift Package Manager:
dependencies:[.package(url:"https://github.com/alexruperez/StateMachine.git")]
classMyState:State{func isValidNext<S>(state type:S.Type)->Boolwhere S:State{switch type{case isOneValidNextState.Type, isOtherValidNextState.Type:returntruedefault:returnfalse}}}classOneValidNextState:State{func isValidNext<S>(state type:S.Type)->Boolwhere S:State{return type isOtherValidNextState.Type}func didEnter(from previous:State?){ // Your code here}}classOtherValidNextState:State{func isValidNext<S>(state type:S.Type)->Boolwhere S:State{returnfalse}func willExit(to next:State){ // Your code here}}
letstateMachine=StateMachine([MyState(),OneValidNextState(),OtherValidNextState()])stateMachine.enter(OneValidNextState.self)stateMachine.enter(OtherValidNextState.self)
letsubscriptionToken= stateMachine.subscribe{(previous, current)in // Your code here}stateMachine.unsubscribe(subscriptionToken)stateMachine.unsubscribeAll()
UIApplication and UIApplicationDelegate extensions with application life cycle State Machine embedded:
ifUIApplication.shared.stateMachine.current isActiveApplicationState{ // Your code here}
letviewController=StatefulViewController()if viewController.stateMachine.current isAppearingViewControllerState{ // Your code here}
- Contributions are very welcome.
- Attribution is appreciated (let's spread the word!), but not mandatory.
alexruperez,contact@alexruperez.com
StateMachine is available under the MIT license. See the LICENSE file for more info.
About
State machine creation framework written in Swift inspired by GKStateMachine from Apple GameplayKit
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
No packages published


