Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StateMachine

StateMachine

TwitterVersionLicensePlatformSwiftCarthage compatibleSwift Package Manager CompatibleBuild Statuscodecovcodebeat badgeBCH compliance

Swift library to createFinite-state machines inspired byGKStateMachine from AppleGameplayKit framework.

Test StateMachine working live!

🌟 Features

  • 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.

📲 Installation

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")]

🐒 Usage

Define States and Their Behavior:

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}}

Create and Drive a State Machine:

letstateMachine=StateMachine([MyState(),OneValidNextState(),OtherValidNextState()])stateMachine.enter(OneValidNextState.self)stateMachine.enter(OtherValidNextState.self)

Subscribe/unsubscribe to State changes:

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:

UIApplication

ifUIApplication.shared.stateMachine.current isActiveApplicationState{    // Your code here}

StatefulViewController subclass with UIViewController life cycle State Machine embedded:

StatefulViewController

letviewController=StatefulViewController()if viewController.stateMachine.current isAppearingViewControllerState{    // Your code here}

❤️ Etc.

  • Contributions are very welcome.
  • Attribution is appreciated (let's spread the word!), but not mandatory.

👨‍💻 Authors

alexruperez,contact@alexruperez.com

👮‍♂️ License

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

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp