Skip to content

Commit

Permalink
Merge pull request #4 from cipriancaba/swift-2.0
Browse files Browse the repository at this point in the history
Swift 2.*
  • Loading branch information
cipriancaba committed May 24, 2016
2 parents 4525dc7 + a3eeae5 commit a03ea41
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 27 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# * https://github.com/supermarin/xcpretty#usage

language: objective-c
osx_image: xcode6.4
osx_image: xcode7.3
cache: cocoapods
podfile: Example/Podfile
before_install:
Expand All @@ -14,6 +14,6 @@ install:
- gem install xcpretty --no-rdoc --no-ri --no-document --quiet
script:
- set -o pipefail
- xcodebuild test -workspace Example/SwiftFSM.xcworkspace -scheme SwiftFSM-Example -sdk "iphonesimulator8.4" -destination "OS=8.4,name=iPhone 6 Plus" ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild build -workspace Example/SwiftFSM.xcworkspace -scheme SwiftFSM-Example -sdk "iphonesimulator8.4" -destination "OS=8.4,name=iPhone 6 Plus" ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild test -workspace Example/SwiftFSM.xcworkspace -scheme SwiftFSM-Example -sdk "iphonesimulator9.3" -destination "OS=9.3,name=iPhone 6 Plus" ONLY_ACTIVE_ARCH=NO | xcpretty -c
- xcodebuild build -workspace Example/SwiftFSM.xcworkspace -scheme SwiftFSM-Example -sdk "iphonesimulator9.3" -destination "OS=9.3,name=iPhone 6 Plus" ONLY_ACTIVE_ARCH=NO | xcpretty -c
- pod lib lint --quick
6 changes: 2 additions & 4 deletions Example/Podfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
source 'https://github.com/CocoaPods/Specs.git'
use_frameworks!

target 'SwiftFSM_Example', :exclusive => true do
target 'SwiftFSM_Example' do
pod "SwiftFSM", :path => "../"
end

target 'SwiftFSM_Tests', :exclusive => true do
target 'SwiftFSM_Tests' do
pod "SwiftFSM", :path => "../"


end
7 changes: 6 additions & 1 deletion Example/SwiftFSM.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0630;
LastUpgradeCheck = 0730;
ORGANIZATIONNAME = CocoaPods;
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
Expand Down Expand Up @@ -443,6 +443,7 @@
COPY_PHASE_STRIP = NO;
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
Expand Down Expand Up @@ -511,6 +512,7 @@
INFOPLIST_FILE = SwiftFSM/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
Expand All @@ -523,6 +525,7 @@
INFOPLIST_FILE = SwiftFSM/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
Expand All @@ -542,6 +545,7 @@
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftFSM_Example.app/SwiftFSM_Example";
};
Expand All @@ -558,6 +562,7 @@
);
INFOPLIST_FILE = Tests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = "org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)";
PRODUCT_NAME = "$(TARGET_NAME)";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SwiftFSM_Example.app/SwiftFSM_Example";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0630"
LastUpgradeVersion = "0730"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down Expand Up @@ -37,10 +37,10 @@
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
buildConfiguration = "Debug">
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
Expand All @@ -62,15 +62,18 @@
ReferencedContainer = "container:SwiftFSM.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
buildConfiguration = "Debug"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand All @@ -86,10 +89,10 @@
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
buildConfiguration = "Release"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftFSM/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.cocoapods.demo.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftFSM/TurnstileState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum TurnstileState: String {
case Unlocked = "Unlocked"
}

extension TurnstileState: Printable {
extension TurnstileState: CustomStringConvertible {
var description: String {
get {
switch self {
Expand Down
2 changes: 1 addition & 1 deletion Example/SwiftFSM/TurnstileTransition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ enum TurnstileTransition: String {
case Coin = "Coin"
}

extension TurnstileTransition: Printable {
extension TurnstileTransition: CustomStringConvertible {
var description: String {
get {
switch self {
Expand Down
4 changes: 2 additions & 2 deletions Example/SwiftFSM/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ class ViewController: UIViewController {

func append(message: String) {
stateTextView.text = "\(self.stateTextView.text)\n\(message)"
stateTextView.scrollRangeToVisible(NSMakeRange(count(stateTextView.text), 1))
stateTextView.scrollRangeToVisible(NSMakeRange(stateTextView.text.characters.count - 1, 1))
}

@IBAction func onCoin(sender: AnyObject) {
if let newState = fsm.transitionWith(.Coin) {
if let _ = fsm.transitionWith(.Coin) {
// state change happened
} else {
// transition was not valid
Expand Down
2 changes: 1 addition & 1 deletion Example/Tests/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>org.cocoapods.$(PRODUCT_NAME:rfc1034identifier)</string>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
Expand Down
10 changes: 5 additions & 5 deletions Example/Tests/Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ class Tests: XCTestCase {
let unlocked = fsm.addState(.Unlocked)

unlocked.onEnter = { (transition: TurnstileTransition) -> Void in
XCTAssertEqual(transition, .Coin, "Fsm did not entered the unlocked state with the .Coin transition")
XCTAssertEqual(transition, TurnstileTransition.Coin, "Fsm did not entered the unlocked state with the .Coin transition")
expectationUnlockedEntered.fulfill()
}

fsm.transitionWith(.Coin)

waitForExpectationsWithTimeout(3, handler: { (error) -> Void in
if let error = error {
println("Error: \(error.localizedDescription)")
print("Error: \(error.localizedDescription)")
}
})
}
Expand All @@ -50,7 +50,7 @@ class Tests: XCTestCase {

let unlocked = fsm.addState(.Unlocked)
unlocked.onExit = { (transition: TurnstileTransition) -> Void in
XCTAssertEqual(transition, .Push, "Fsm did not exited the unlocked state with the .Push transition")
XCTAssertEqual(transition, TurnstileTransition.Push, "Fsm did not exited the unlocked state with the .Push transition")
expectationUnlockedExited.fulfill()
}

Expand All @@ -62,7 +62,7 @@ class Tests: XCTestCase {

waitForExpectationsWithTimeout(3, handler: { (error) -> Void in
if let error = error {
println("Error: \(error.localizedDescription)")
print("Error: \(error.localizedDescription)")
}
})
}
Expand All @@ -71,7 +71,7 @@ class Tests: XCTestCase {
// This needs to transition to unlocked
if let newState = fsm.transitionWith(.Coin) {
XCTAssertEqual(fsm.currentState, newState, "Fsm currentState is not the same with the returned state")
XCTAssertEqual(fsm.currentState, .Unlocked, "Fsm did not transition to unlocked")
XCTAssertEqual(fsm.currentState, TurnstileState.Unlocked, "Fsm did not transition to unlocked")
} else {
XCTFail("Fsm has not transitioned at all")
}
Expand Down
Empty file removed Pod/Classes/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion Pod/Classes/SwiftFSM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class SwiftFSM<State: Hashable, Transition: Hashable> {

private func log(message: String) {
if _willLog {
println("\(_id) \(message)")
print("\(_id) \(message)")
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ $ pod install

### Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate SwiftFSM into your project manually by simply copying [SwiftFSM.swift](https://github.com/cipriancaba/SwiftFSM/blob/master/Pod/Classes/SwiftFSM.swift) into your project
If you prefer not to use either of the aforementioned dependency managers, you can integrate SwiftFSM into your project manually by simply copying [SwiftFSM.swift](https://github.com/cipriancaba/SwiftFSM/blob/master/Pod/Classes/SwiftFSM.swift) and [SwiftFSMState.swift](https://github.com/cipriancaba/SwiftFSM/blob/master/Pod/Classes/SwiftFSMState.swift) into your project

## Usage

Expand Down
2 changes: 1 addition & 1 deletion SwiftFSM.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "SwiftFSM"
s.version = "0.2.0"
s.version = "0.2.1"
s.summary = "A solid yet simple fsm implementation in Swift"
s.description = <<-DESC
Finit state machine implementation using Enums, Generics and Closures
Expand Down

0 comments on commit a03ea41

Please sign in to comment.