Skip to content

Commit

Permalink
Dropped Swift 2.x support
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Knabel committed Sep 8, 2016
1 parent 584363e commit b74599b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ author: Valentin Knabel
author_url: https://twitter.com/vknabel
github_url: https://github.com/vknabel/Finite
module: Finite
module_version: 2.0.0
module_version: 3.0.0
root_url: https://vknabel.github.io/Finite/
readme: README.md
output: docs/
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# 3.0.0
*Released: 2016-09-08*

**Breaking Changes:**
- Dropped Swift 2.2 and 2.3 support - @vknabel

# 2.0.0
*Released: 2016-08-22*

Expand Down
2 changes: 1 addition & 1 deletion Finite.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Finite'
s.version = '2.0.0'
s.version = '3.0.0'
s.summary = 'A simple state machine written in Swift.'
s.description = <<-DESC
Finite is a simple, pure Swift finite state machine.
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# 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.0.0` only supports Swift `3.0`.

## Installation
EasyInject is a Swift only project and supports [Swift Package Manager](https://github.com/apple/swift-package-manager), [Carthage](https://github.com/Carthage/Carthage) and [CocoaPods](https://github.com/CocoaPods/CocoaPods).
Expand All @@ -17,7 +18,7 @@ import PackageDescription
let package = Package(
name: "YourPackage",
dependencies: [
.Package(url: "https://github.com/vknabel/EasyInject.git", majorVersion: 2)
.Package(url: "https://github.com/vknabel/EasyInject.git", majorVersion: 3)
]
)
```
Expand Down
31 changes: 5 additions & 26 deletions Sources/StateFlow.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public struct StateFlow<T: Hashable> {
- parameter transition: The transition allowing less-equal transitions.
- parameter filter: An optional filter for transitions.
*/
public mutating func allow(transition transition: Transition<T>, filter: TransitionFilter? = nil) {
public mutating func allow(transition: Transition<T>, filter: TransitionFilter? = nil) {
if transitionFilters[transition] == nil {
transitionFilters[transition] = filter
}
}

#if swift(>=3.0)
/**
Returns wether a specific transition is allowed or not.
Invokes defined transition filters until one returned true or a transition is unconditioned.
Expand All @@ -60,26 +59,6 @@ public struct StateFlow<T: Hashable> {
}
return false
}
#else
/**
Returns wether a specific transition is allowed or not.
Invokes defined transition filters until one returned true or a transition is unconditioned.
- parameter transition: The transition to be tested.
- returns: Returns true if a more-equal transition is allowed.
*/
public func allows(transition: Transition<T>) -> Bool {
for _ in transition.generalTransitions {
if let opf = transitionFilters[transition] {
let succ = opf?(transition) ?? true
if succ {
return true
}
}
}
return false
}
#endif
}

public extension StateFlow {
Expand All @@ -90,7 +69,7 @@ public extension StateFlow {
- parameter from: The source state.
- parameter filter: An optional filter for transitions.
*/
public mutating func allow(from from: T, filter: TransitionFilter? = nil) {
public mutating func allow(from: T, filter: TransitionFilter? = nil) {
self.allow(transition: Transition<T>(from: from, to: nil), filter: filter)
}

Expand All @@ -100,7 +79,7 @@ public extension StateFlow {
- parameter to: The target state.
- parameter filter: An optional filter for transitions.
*/
public mutating func allow(to to: T, filter: TransitionFilter? = nil) {
public mutating func allow(to: T, filter: TransitionFilter? = nil) {
self.allow(transition: Transition<T>(from: nil, to: to), filter: filter)
}

Expand All @@ -111,7 +90,7 @@ public extension StateFlow {
- parameter to: The target state.
- parameter filter: An optional filter for transitions.
*/
public mutating func allow(from from: T, to: T, filter: TransitionFilter? = nil) {
public mutating func allow(from: T, to: T, filter: TransitionFilter? = nil) {
self.allow(transition: Transition<T>(from: from, to: to), filter: filter)
}

Expand All @@ -121,7 +100,7 @@ public extension StateFlow {
- parameter from: All source states.
- parameter filter: An optional filter for transitions.
*/
public mutating func allow(from from: [T], filter: TransitionFilter? = nil) {
public mutating func allow(from: [T], filter: TransitionFilter? = nil) {
for f in from {
self.allow(transition: Transition<T>(from: f, to: nil), filter: filter)
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/StateMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public struct StateMachine<T: Hashable> {
- throws: Either TransitionError or rethrows underlying errors.
- returns: Wether the transition could be performed or not.
*/
public mutating func transition(to to: T, completion: Operation? = nil) throws {
public mutating func transition(to: T, completion: Operation? = nil) throws {
let transition = self.transition(to)
if configuration.allows(transition) {
for t in transition.generalTransitions {
Expand All @@ -89,7 +89,7 @@ public struct StateMachine<T: Hashable> {
- parameter to: The targeted state.
- returns: true if allowed else false.
*/
public func allows(to to: T) -> Bool {
public func allows(to: T) -> Bool {
return configuration.allows(self.transition(to))
}

Expand All @@ -99,7 +99,7 @@ public struct StateMachine<T: Hashable> {
- parameter transition: The most specific transition.
- parameter perform: The operation the be performed.
*/
public mutating func onTransitions(transition transition: Transition<T>, perform op: Operation) {
public mutating func onTransitions(transition: Transition<T>, perform op: @escaping Operation) {
if transitionHandlers[transition] == nil {
transitionHandlers[transition] = []
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public extension StateMachine {
- parameter to: The target state.
- parameter perform: The operation the be performed.
*/
public mutating func onTransitions(from from: T, to: T, perform op: Operation) {
public mutating func onTransitions(from: T, to: T, perform op: @escaping Operation) {
let transition = Transition<T>(from: from, to: to)
if transitionHandlers[transition] == nil {
transitionHandlers[transition] = []
Expand All @@ -145,7 +145,7 @@ public extension StateMachine {
- parameter from: The source state.
- parameter perform: The operation the be performed.
*/
public mutating func onTransitions(from from: T, perform op: Operation) {
public mutating func onTransitions(from: T, perform op: @escaping Operation) {
let transition = Transition<T>(from: from, to: nil)
if transitionHandlers[transition] == nil {
transitionHandlers[transition] = []
Expand All @@ -159,7 +159,7 @@ public extension StateMachine {
- parameter to: The target state.
- parameter perform: The operation the be performed.
*/
public mutating func onTransitions(to to: T, perform op: Operation) {
public mutating func onTransitions(to: T, perform op: @escaping Operation) {
let transition = Transition<T>(from: nil, to: to)
if transitionHandlers[transition] == nil {
transitionHandlers[transition] = []
Expand Down

0 comments on commit b74599b

Please sign in to comment.