Skip to content

Commit

Permalink
Support multiple platforms + Swift Package Manager (#3)
Browse files Browse the repository at this point in the history
* Reorganise folders for SPM support and multiple platforms

* Default associated type for cleaner conformances

* Update readme

* Update readme

* Run CI on multiple platforms

* test

* Test

* Fix linux tests

* Restore all travis builds

* Fix pod warnings
  • Loading branch information
jordanhamill authored Oct 3, 2017
1 parent 7098915 commit 2a24f64
Show file tree
Hide file tree
Showing 36 changed files with 1,311 additions and 386 deletions.
94 changes: 40 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@

# Created by https://www.gitignore.io/api/xcode,macos,carthage,cocoapods

### Carthage ###
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

### CocoaPods ###
## CocoaPods GitIgnore Template

# CocoaPods - Only use to conserve bandwidth / Save time on Pushing
# - Also handy if you have a lage number of dependant pods
# - AS PER https://guides.cocoapods.org/using/using-cocoapods.html NEVER IGONRE THE LOCK FILE
Pods/

### macOS ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Xcode ###
# Xcode
#
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
Expand All @@ -69,13 +22,46 @@ xcuserdata/
*.xccheckout
*.xcscmblueprint

### Xcode Patch ###
*.xcodeproj/*
!*.xcodeproj/project.pbxproj
!*.xcodeproj/xcshareddata/
!*.xcworkspace/contents.xcworkspacedata
/*.gcno
## Obj-C/Swift specific
*.hmap
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

# Swift Package Manager
#
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
# Packages/
# Package.pins
.build/

# CocoaPods
#
# We recommend against adding the Pods directory to your .gitignore. However
# you should judge for yourself, the pros and cons are mentioned at:
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
#
# Pods/

# End of https://www.gitignore.io/api/xcode,macos,carthage,cocoapods
# Carthage
#
# Add this line if you want to avoid checking in source code from Carthage dependencies.
# Carthage/Checkouts

Carthage/Build

# fastlane
#
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
# screenshots whenever they are needed.
# For more information about the recommended setup visit:
# https://docs.fastlane.tools/best-practices/source-control/#source-control

fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4
4.0
39 changes: 31 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
language: objective-c
osx_image: xcode9

before_script:
- export LANG=en_US.UTF-8
script:
- xcodebuild -project Stated.xcodeproj clean
- travis_retry xcodebuild -project Stated.xcodeproj -scheme Stated -destination 'platform=iOS Simulator,name=iPhone 7' -configuration Debug test
matrix:
include:
- language: objective-c
osx_image: xcode9
before_script:
- export LANG=en_US.UTF-8

script:
- xcodebuild -project Stated.xcodeproj clean
- travis_retry xcodebuild -project Stated.xcodeproj -scheme Stated-iOS -destination 'platform=iOS Simulator,name=iPhone 7' -configuration Debug test

- language: objective-c
osx_image: xcode9
before_script:
- export LANG=en_US.UTF-8

script:
- xcodebuild -project Stated.xcodeproj clean
- travis_retry xcodebuild -project Stated.xcodeproj -scheme Stated-macOS -configuration Debug test

- language: generic
os: linux
sudo: required
dist: trusty
install:
- eval "$(curl -sL https://gist.githubusercontent.com/kylef/5c0475ff02b7c7671d2a/raw/9f442512a46d7a2af7b850d65a7e9bd31edfb09b/swiftenv-install.sh)"
- swiftenv install https://swift.org/builds/swift-4.0-release/ubuntu1404/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu14.04.tar.gz
- swift build

script:
- swift test
6 changes: 5 additions & 1 deletion Stated/Info.plist → Configs/Stated.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>1.1.0</string>
<string>1.2.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2017 Jordan Hamill. All rights reserved.</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
Expand Down
2 changes: 2 additions & 0 deletions StatedTests/Info.plist → Configs/StatedTests.plist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
Expand Down
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
The MIT License (MIT)

Copyright (c) 2017 Jordan Hamill

Expand All @@ -19,3 +19,4 @@ 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.

5 changes: 5 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import PackageDescription

let package = Package(
name: "Stated"
)
54 changes: 24 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
# Stated
A simple state machine implementation with an API shamelessly based upon [RxAutomaton](https://github.com/inamiy/RxAutomaton).
A simple state machine implementation with a beautiful DSL.

State transitions cause effects that can send a new input to the state machine, errors can be represented by new states and inputs.
Each state conforms to one of `State`, `SimpleState`, `StateTakingInput` or `StateUsingMappedState`. A state object can receive arguments from a defined input. It can also be passed anything from the previous state

The DSL was inspired by [RxAutomaton](https://github.com/inamiy/RxAutomaton).

[![Build Status](https://travis-ci.org/jordanhamill/Stated.svg?branch=master)](https://travis-ci.org/jordanhamill/Stated)
![Swift Package Manager Compatible](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)
[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
![CocoaPods Compatible](https://img.shields.io/badge/pod-ios%20%7C%20macos%20%7C%20watchos%20%7C%20tvos-lightgrey.svg)

## Example State Machine

App delegates can very quickly become a real handful based on the different initial screens that can appear.
Expand All @@ -20,35 +27,12 @@ class AppLauncher {

// MARK: Create some simple states that hold no data.

struct UninitializedState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}

struct InitializedState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}

struct UpgradingState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}

struct IndexingState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}

struct LoggedInState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}

struct LoggedOutState: SimpleState {
public typealias Arguments = Void
public typealias MappedState = Void
}
struct UninitializedState: SimpleState { }
struct InitializedState: SimpleState { }
struct UpgradingState: SimpleState { }
struct IndexingState: SimpleState { }
struct LoggedInState: SimpleState { }
struct LoggedOutState: SimpleState { }

// MARK: Define the states we're going to use by creating "slots" in which the system can place a given instance of one of our states

Expand Down Expand Up @@ -217,3 +201,13 @@ Run the following command:
```
$ carthage update
```

### Swift Package Manager

Add Stated as a dependency to your `package.swift`

```
dependencies: [
.Package(url: "https://github.com/jordanhamill/Stated.git", majorVersion: 1)
]
```
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

extension InputSlot {
///
/// Define the current state the system must be in for a valid transition.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ public typealias NoArguments = Void
///
///
public protocol State: AnyState {
associatedtype Arguments
associatedtype MappedState
associatedtype Arguments = NoArguments
associatedtype MappedState = Void

static func create(arguments: Arguments, state: MappedState) -> Self
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 11 additions & 11 deletions Stated.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |spec|
spec.name = 'Stated'
spec.version = '1.1.0'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://github.com/jordanhamill/StateMachine'
spec.authors = { 'Jordan Hamill' => '[email protected]' }
spec.summary = 'Swift state machine with a beautiful DSL'
spec.source = { :git => 'https://github.com/jordanhamill/StateMachine.git', :tag => '1.1.0' }
spec.source_files = 'Stated/**/*.{swift}'

spec.ios.deployment_target = '10.0'
Pod::Spec.new do |s|
s.name = 'Stated'
s.version = '1.2.0'
s.summary = 'Swift state machine with a beautiful DSL'
s.homepage = 'https://github.com/jordanhamill/StateMachine'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.author = { 'Jordan Hamill' => '[email protected]' }
s.ios.deployment_target = '10.0'
s.osx.deployment_target = '10.9'
s.source = { :git => 'https://github.com/jordanhamill/StateMachine.git', :tag => s.version.to_s }
s.source_files = 'Sources/**/*'
end
Loading

0 comments on commit 2a24f64

Please sign in to comment.