Skip to content

Commit

Permalink
[feature] Validate Swift 4 support
Browse files Browse the repository at this point in the history
  • Loading branch information
vknabel committed Oct 6, 2017
1 parent 07f441d commit 14019dd
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 15 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
.DS_Store
._*

# VS Code
## Settings
.vscode

# Xcode
## Build generated
.build/
Expand Down
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0
4.0
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,34 @@ notifications:
email: false
matrix:
include:
- os: osx
osx_image: xcode9
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

- os: osx
osx_image: xcode8
env:
- SWIFT_VERSION=3.0
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

- os: linux
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
- swift build
- swift test

- os: linux
env:
- SWIFT_VERSION=3.0
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
script:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 3.0.3

*Released: 2017-10-06*

### Other Changes

- Readme updates - @vknabel
- Proven Swift 4.0 support - @vknabel

## 3.0.2

*Released: 2016-09-26*
Expand Down
4 changes: 2 additions & 2 deletions Finite.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |s|
s.name = 'Finite'
s.version = '3.0.2'
s.version = '3.0.3'
s.summary = 'A simple state machine written in Swift.'
s.description = <<-DESC
Finite is a simple, pure Swift finite state machine.
DESC
s.social_media_url = "https://twitter.com/vknabel"
s.homepage = 'https://github.com/vknabel/Finite'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Valentin Knabel' => 'develop@vknabel.com' }
s.author = { 'Valentin Knabel' => 'dev@vknabel.com' }
s.source = { :git => 'https://github.com/vknabel/Finite.git', :tag => s.version.to_s }
s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
Expand Down
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
# Finite

Finite is a simple, pure Swift finite state machine. Only exlicitly allowed transitions between states are allowed, otherwise an error will be thrown.
Version `2.0.0` supports Swift `2.2` and `3.0 Beta`, whereas Finite `3.x.x` only supports Swift `3.0`.

| **Finite** | **Swift** |
|------------|----------------------|
| `2.0.0` | `2.2` and `3.0 Beta` |
| `3.x.x` | `3.0` and `4.0` |

## Installation

Expand Down Expand Up @@ -46,45 +50,45 @@ It operates on a given type, where each value represents an internal state of th

```swift
enum Test: Int {
case Saving, Fetching, Deleting
case saving, Fetching, Deleting
case Ready, Fail
}

var machine = StateMachine<Test>(initial: .Ready) { c in
c.allow(from: [.Saving, .Fetching, .Deleting], to: [.Ready, .Fail])
c.allow(from: .Ready, to: [.Saving, .Fetching, .Deleting])
var machine = StateMachine<Test>(initial: .ready) { c in
c.allow(from: [.saving, .fetching, .deleting], to: [.ready, .fail])
c.allow(from: .ready, to: [.saving, .fetching, .deleting])
}
```

It is possible to provide callbacks, that will be called once certain transitions will happen.

```swift
machine.onTransitions(from: .Ready) {
machine.onTransitions(from: .ready) {
println("From Ready: show activity indicator")
}
machine.onTransitions(to: .Ready) {
machine.onTransitions(to: .ready) {
println("To Ready: hide activity indicator")
}
machine.onTransitions(to: .Saving) {
machine.onTransitions(to: .saving) {
println("To: save")
}
```

Once the `StateMachine` has been set up, you may trigger all transitions you have declared above.

```swift
try machine.transition(to: .Saving) {
try machine.transition(to: .saving) {
println("Triggered: save")
}

// this will throw an error
try machine.transition(to: .Fetching)
try machine.transition(to: .fetching)
```

## Author

Valentin Knabel, develop@vknabel.com
Valentin Knabel, dev@vknabel.com

## License

Finite is available under the MIT license. See the LICENSE file for more info.
Finite is available under the [MIT](./LICENSE) license.

0 comments on commit 14019dd

Please sign in to comment.