Skip to content

Commit

Permalink
First release
Browse files Browse the repository at this point in the history
  • Loading branch information
softwarenerd committed Nov 23, 2016
0 parents commit 299e888
Show file tree
Hide file tree
Showing 22 changed files with 2,402 additions and 0 deletions.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Mac OS X
*.DS_Store


# Xcode
*.pbxuser
*.mode2v3
*.mode1v3
*.perspective
*.perspectivev3
*.xcuserstate
xcuserdata/

## Generic Files To Ignore
*~
*.swp
*.out

# Carthage
Carthage/Checkouts
*.bcsymbolmap

AppStoreBuild

.vscode
12 changes: 12 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
language: objective-c

branches:
only:
- master

xcode_project: Stately.xcodeproj
xcode_scheme: macOSStately
osx_image: xcode8.1

script:
- xcodebuild clean build test -project Stately.xcodeproj -scheme macOSStately
Binary file added Documentation/AddFramework.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2016 Softwarenerd.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file added Logo/Header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
![](Logo/Header.png)

# Stately [![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/softwarenerd/Stately/master/LICENSE.md) [![GitHub release](https://img.shields.io/github/release/softwarenerd/Stately.svg)](https://github.com/softwarenerd/Stately/releases) [![Build Status](https://travis-ci.org/softwarenerd/Stately.svg?branch=master)](https://travis-ci.org/softwarenerd/Stately)

## Introduction

[Stately](https://github.com/softwarenerd/Stately) is a pure Swift framework for iOS, macOS, watchOS, and tvOS that implements an event-driven finite-state machine.

For information on finite-state machines, see the Wikipedia article [Finite-state machine](https://en.wikipedia.org/wiki/Finite-state_machine).

## Background

I have used variations of Stately in numerous iOS, macOS and .NET applications, and I've found it to be an invaluable tool. I created this open-source version of it for iOS, macOS, watchOS, and tvOS so that other people can both benefit from it and contribute to it.

### Objective-C Compatibility

At this time, Stately cannot be used with Objective-C projects. I decided that it makes the most sense to share Stately as a pure Swift framework. If it becomes clear that Objective-C compatibility is needed, I will add it.

## Quick Links

- [Getting Started](#getting-started)
- [Basic Documentation](#basic-documentation)
- [Example Project](#example-project)
- [Contributing](#contributing)
- [License](#license)

## Getting Started

Stately can be used via [Carthage](https://github.com/Carthage/Carthage).

There are excellent [Insructions](https://github.com/Carthage/Carthage#getting-started) available on the [Carthage](https://github.com/Carthage/Carthage) site, which are summarized below.

#### Add Stately to your Cartfile

```
github "softwarenerd/Stately"
```

#### Update Carthage

```sh
carthage update
```

This will fetch dependencies into a `Carthage/Checkouts` folder, then build each one.

#### Using Stately - macOS

On your application targets’ “General” settings tab, in the “Embedded Binaries” section, drag and drop the Stately.framework file from the [Carthage/Build/Mac][] folder on disk.

Additionally, you'll need to copy debug symbols for debugging and crash reporting on OS X.

#### Using Stately - iOS, tvOS, watchOS

1. On your application targets’ “General” settings tab, in the “Linked Frameworks and Libraries” section, drag and drop Stately.framework you want to use from the appropriate [Carthage/Build][] folder on disk.
1. On your application targets’ “Build Phases” settings tab, click the “+” icon and choose “New Run Script Phase”. Create a Run Script in which you specify your shell (ex: `bin/sh`), add the following contents to the script area below the shell:

```sh
/usr/local/bin/carthage copy-frameworks
```

and add the paths to the frameworks you want to use under “Input Files”, e.g.:

```
$(SRCROOT)/Carthage/Build/iOS/Stately.framework
```

This script works around an [App Store submission bug](http://www.openradar.me/radar?id=6409498411401216) triggered by universal binaries and ensures that necessary bitcode-related files and dSYMs are copied when archiving.

With the debug information copied into the built products directory, Xcode will be able to symbolicate the stack trace whenever you stop at a breakpoint.

When archiving your application for submission to the App Store or TestFlight, Xcode will also copy these files into the dSYMs subdirectory of your application’s `.xcarchive` bundle.

## Basic Documentation

Using [Stately](https://github.com/softwarenerd/Stately) is easy and straightforward.

```swift
var stateClosed: State!
var stateOpened: State!
var eventOpen: Event!
var eventClose: Event!
var stateMachine: StateMachine!
do {
// Define the states that the state machine can be in.
stateClosed = try State(name: "Closed") { (object: AnyObject?) -> StateChange? in
// Log.
print("Closed")
// Return, leaving state unchanged.
return nil
}
stateOpened = try State(name: "Opened") { (object: AnyObject?) -> StateChange? in
// Log.
print("Opened")
// Return, leaving state unchanged.
return nil
}
// Define the events that can be sent to the state machine.
eventOpen = try Event(name: "Open", transitions: [(fromState: stateClosed, toState: stateOpened)])
eventClose = try Event(name: "Close", transitions: [(fromState: stateOpened, toState: stateClosed)])
// Initialize the state machine.
stateMachine = try StateMachine(name: "Door",
defaultState: stateClosed,
states: [stateClosed, stateOpened],
events: [eventClose, eventOpen])
// Fire events to the state machine.
stateMachine.fireEvent(event: eventOpen)
stateMachine.fireEvent(event: eventClose)
} catch {
// Handle errors.
}
```

## Example Project

The [StatelyExample](https://github.com/softwarenerd/StatelyExample) project provides a comprehensive example of using Stately to build a garage door simulator.

## Contributing

Stately is a work in progress and your contributions are most welcome. Feel free to fork the repo and submit PR's.
## License
Stately is released under the [MIT License](LICENSE.md).
Loading

0 comments on commit 299e888

Please sign in to comment.