{"id":24903895,"url":"https://github.com/alexruperez/statemachine","last_synced_at":"2025-10-16T15:30:57.137Z","repository":{"id":56902409,"uuid":"118371386","full_name":"alexruperez/StateMachine","owner":"alexruperez","description":"State machine creation framework written in Swift inspired by GKStateMachine from Apple GameplayKit","archived":false,"fork":false,"pushed_at":"2018-01-28T12:42:05.000Z","size":1651,"stargazers_count":48,"open_issues_count":0,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-01-23T10:03:30.948Z","etag":null,"topics":["finite","finite-state-automata","finite-state-machine","framework","gameplay","gameplaykit","gkstatemachine","machine","state","state-machine","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexruperez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-21T20:32:28.000Z","updated_at":"2023-08-22T01:21:42.000Z","dependencies_parsed_at":"2022-08-20T18:50:27.362Z","dependency_job_id":null,"html_url":"https://github.com/alexruperez/StateMachine","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexruperez%2FStateMachine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexruperez%2FStateMachine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexruperez%2FStateMachine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexruperez%2FStateMachine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexruperez","download_url":"https://codeload.github.com/alexruperez/StateMachine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":236730802,"owners_count":19195683,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["finite","finite-state-automata","finite-state-machine","framework","gameplay","gameplaykit","gkstatemachine","machine","state","state-machine","swift"],"created_at":"2025-02-01T22:34:29.492Z","updated_at":"2025-10-16T15:30:51.724Z","avatar_url":"https://github.com/alexruperez.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![StateMachine](https://raw.githubusercontent.com/alexruperez/StateMachine/master/Logo.png)\n# StateMachine\n\n[![Twitter](https://img.shields.io/badge/contact-@alexruperez-0FABFF.svg?style=flat)](http://twitter.com/alexruperez)\n[![Version](https://img.shields.io/cocoapods/v/ArchitStateMachine.svg?style=flat)](http://cocoapods.org/pods/ArchitStateMachine)\n[![License](https://img.shields.io/cocoapods/l/ArchitStateMachine.svg?style=flat)](http://cocoapods.org/pods/ArchitStateMachine)\n[![Platform](https://img.shields.io/cocoapods/p/ArchitStateMachine.svg?style=flat)](http://cocoapods.org/pods/ArchitStateMachine)\n[![Swift](https://img.shields.io/badge/Swift-4-orange.svg?style=flat)](https://swift.org)\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![Swift Package Manager Compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-4BC51D.svg?style=flat)](https://github.com/apple/swift-package-manager)\n[![Build Status](https://travis-ci.org/alexruperez/StateMachine.svg?branch=master)](https://travis-ci.org/alexruperez/StateMachine)\n[![codecov](https://codecov.io/gh/alexruperez/StateMachine/branch/master/graph/badge.svg)](https://codecov.io/gh/alexruperez/StateMachine)\n[![codebeat badge](https://codebeat.co/badges/58cefb6d-519e-4277-a05f-1b7e1a7f7835)](https://codebeat.co/projects/github-com-alexruperez-statemachine-master)\n[![BCH compliance](https://bettercodehub.com/edge/badge/alexruperez/StateMachine?branch=master)](https://bettercodehub.com/)\n\nSwift library to create [**Finite-state machines**](https://en.wikipedia.org/wiki/Finite-state_machine) inspired by [GKStateMachine](https://developer.apple.com/documentation/gameplaykit/gkstatemachine) from Apple [GameplayKit](https://developer.apple.com/library/content/documentation/General/Conceptual/GameplayKit_Guide/StateMachine.html) framework.\n\n[**Test StateMachine working live!**](https://appetize.io/app/1rzk2knb6927f4m08vpjtg4mmr?device=iphone8\u0026scale=75\u0026orientation=landscape\u0026osVersion=11.1\u0026deviceColor=black)\n\n## 🌟 Features\n\n- [x] Define States and Their Behavior.\n- [x] Create and Drive a State Machine.\n- [x] Subscribe/unsubscribe to State changes.\n- [x] UIApplication and UIApplicationDelegate extensions with application life cycle State Machine embedded.\n- [x] StatefulViewController subclass with UIViewController life cycle State Machine embedded.\n\n## 📲 Installation\n\nStateMachine is available through [CocoaPods](http://cocoapods.org). To install\nit, simply add the following line to your Podfile:\n\n```ruby\npod 'ArchitStateMachine'\n```\n\n#### Or you can install it with [Carthage](https://github.com/Carthage/Carthage):\n\n```ogdl\ngithub \"alexruperez/StateMachine\"\n```\n\n#### Or install it with [Swift Package Manager](https://swift.org/package-manager/):\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/alexruperez/StateMachine.git\")\n]\n```\n\n## 🐒 Usage\n\n#### Define States and Their Behavior:\n\n```swift\nclass MyState: State {\n    func isValidNext\u003cS\u003e(state type: S.Type) -\u003e Bool where S : State {\n        switch type {\n        case is OneValidNextState.Type, is OtherValidNextState.Type:\n            return true\n        default:\n            return false\n        }\n    }\n}\n\nclass OneValidNextState: State {\n    func isValidNext\u003cS\u003e(state type: S.Type) -\u003e Bool where S : State {\n        return type is OtherValidNextState.Type\n    }\n\n    func didEnter(from previous: State?) {\n        // Your code here\n    }\n}\n\nclass OtherValidNextState: State {\n    func isValidNext\u003cS\u003e(state type: S.Type) -\u003e Bool where S : State {\n        return false\n    }\n\n    func willExit(to next: State) {\n        // Your code here\n    }\n}\n```\n\n#### Create and Drive a State Machine:\n\n```swift\nlet stateMachine = StateMachine([MyState(), OneValidNextState(), OtherValidNextState()])\n\nstateMachine.enter(OneValidNextState.self)\n\nstateMachine.enter(OtherValidNextState.self)\n```\n\n#### Subscribe/unsubscribe to State changes:\n\n```swift\nlet subscriptionToken = stateMachine.subscribe { (previous, current) in\n    // Your code here\n}\n\nstateMachine.unsubscribe(subscriptionToken)\n\nstateMachine.unsubscribeAll()\n```\n\n#### UIApplication and UIApplicationDelegate extensions with application life cycle State Machine embedded:\n\n![UIApplication](https://raw.githubusercontent.com/alexruperez/StateMachine/master/UIApplication.png)\n\n```swift\nif UIApplication.shared.stateMachine.current is ActiveApplicationState {\n    // Your code here\n}\n```\n\n#### StatefulViewController subclass with UIViewController life cycle State Machine embedded:\n\n![StatefulViewController](https://raw.githubusercontent.com/alexruperez/StateMachine/master/StatefulViewController.png)\n\n```swift\nlet viewController = StatefulViewController()\n\nif viewController.stateMachine.current is AppearingViewControllerState {\n    // Your code here\n}\n```\n\n## ❤️ Etc.\n\n* Contributions are very welcome.\n* Attribution is appreciated (let's spread the word!), but not mandatory.\n\n## 👨‍💻 Authors\n\n[alexruperez](https://github.com/alexruperez), contact@alexruperez.com\n\n## 👮‍♂️ License\n\nStateMachine is available under the MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexruperez%2Fstatemachine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexruperez%2Fstatemachine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexruperez%2Fstatemachine/lists"}