From 7a5da5b9b5da8a5ef51bba7f755b89323250484e Mon Sep 17 00:00:00 2001 From: Adam Yanalunas Date: Wed, 27 Sep 2017 15:09:24 -0700 Subject: [PATCH 01/20] Update project to Xcode 9 suggested settings, fix warnings --- Sources/EventType.swift | 6 +++--- Sources/Machine.swift | 12 ++++++------ Sources/Route.swift | 10 +++++----- Sources/StateMachine.swift | 4 ++-- Sources/StateType.swift | 6 +++--- Sources/Transition.swift | 10 +++++----- Sources/TransitionChain.swift | 16 ++++++++-------- SwiftState.xcodeproj/project.pbxproj | 14 +++++++++++++- .../xcshareddata/xcschemes/SwiftState.xcscheme | 4 +++- Tests/BasicTests.swift | 4 ++-- Tests/MiscTests.swift | 16 ++++++++-------- 11 files changed, 58 insertions(+), 44 deletions(-) diff --git a/Sources/EventType.swift b/Sources/EventType.swift index e696cb6..7266065 100644 --- a/Sources/EventType.swift +++ b/Sources/EventType.swift @@ -49,7 +49,7 @@ extension Event: RawRepresentable } } -public func == (lhs: Event, rhs: Event) -> Bool +public func == (lhs: Event, rhs: Event) -> Bool { switch (lhs, rhs) { case let (.some(x1), .some(x2)) where x1 == x2: @@ -61,7 +61,7 @@ public func == (lhs: Event, rhs: Event) -> Bool } } -public func == (lhs: Event, rhs: E) -> Bool +public func == (lhs: Event, rhs: E) -> Bool { switch lhs { case .some(let x): @@ -71,7 +71,7 @@ public func == (lhs: Event, rhs: E) -> Bool } } -public func == (lhs: E, rhs: Event) -> Bool +public func == (lhs: E, rhs: Event) -> Bool { switch rhs { case .some(let x): diff --git a/Sources/Machine.swift b/Sources/Machine.swift index 8054ac1..8d18824 100644 --- a/Sources/Machine.swift +++ b/Sources/Machine.swift @@ -521,14 +521,14 @@ public class Machine infix operator <-! : AdditionPrecedence @discardableResult -public func <-! (machine: Machine, event: E) -> Machine +public func <-! (machine: Machine, event: E) -> Machine { machine.tryEvent(event) return machine } @discardableResult -public func <-! (machine: Machine, tuple: (E, Any?)) -> Machine +public func <-! (machine: Machine, tuple: (E, Any?)) -> Machine { machine.tryEvent(tuple.0, userInfo: tuple.1) return machine @@ -557,7 +557,7 @@ internal func _createUniqueString() -> String return uniqueString } -internal func _validTransitions(fromState: S, toState: S) -> [Transition] +internal func _validTransitions(fromState: S, toState: S) -> [Transition] { return [ fromState => toState, @@ -567,12 +567,12 @@ internal func _validTransitions(fromState: S, toState: S) -> [Tran ] } -internal func _canPassCondition(_ condition: Machine.Condition?, forEvent event: E?, fromState: S, toState: S, userInfo: Any?) -> Bool +internal func _canPassCondition(_ condition: Machine.Condition?, forEvent event: E?, fromState: S, toState: S, userInfo: Any?) -> Bool { return condition?((event, fromState, toState, userInfo)) ?? true } -internal func _insertHandlerIntoArray(_ handlerInfos: inout [_HandlerInfo], newHandlerInfo: _HandlerInfo) +internal func _insertHandlerIntoArray(_ handlerInfos: inout [_HandlerInfo], newHandlerInfo: _HandlerInfo) { var index = handlerInfos.count @@ -586,7 +586,7 @@ internal func _insertHandlerIntoArray(_ handlerInfos handlerInfos.insert(newHandlerInfo, at: index) } -internal func _removeHandlerFromArray(_ handlerInfos: inout [_HandlerInfo], removingHandlerID: _HandlerID) -> Bool +internal func _removeHandlerFromArray(_ handlerInfos: inout [_HandlerInfo], removingHandlerID: _HandlerID) -> Bool { for i in 0.. //-------------------------------------------------- /// e.g. [.state0, .state1] => .state, allowing [0 => 2, 1 => 2] -public func => (leftStates: [S], right: State) -> Route +public func => (leftStates: [S], right: State) -> Route { // NOTE: don't reuse ".any => .any + condition" for efficiency return Route(transition: .any => right, condition: { context -> Bool in @@ -32,26 +32,26 @@ public func => (leftStates: [S], right: State) -> }) } -public func => (leftStates: [S], right: S) -> Route +public func => (leftStates: [S], right: S) -> Route { return leftStates => .some(right) } /// e.g. .state0 => [.state1, .state], allowing [0 => 1, 0 => 2] -public func => (left: State, rightStates: [S]) -> Route +public func => (left: State, rightStates: [S]) -> Route { return Route(transition: left => .any, condition: { context -> Bool in return rightStates.contains(context.toState) }) } -public func => (left: S, rightStates: [S]) -> Route +public func => (left: S, rightStates: [S]) -> Route { return .some(left) => rightStates } /// e.g. [.state0, .state1] => [.state, .state3], allowing [0 => 2, 0 => 3, 1 => 2, 1 => 3] -public func => (leftStates: [S], rightStates: [S]) -> Route +public func => (leftStates: [S], rightStates: [S]) -> Route { return Route(transition: .any => .any, condition: { context -> Bool in return leftStates.contains(context.fromState) && rightStates.contains(context.toState) diff --git a/Sources/StateMachine.swift b/Sources/StateMachine.swift index 654d9cd..ae8ff6e 100644 --- a/Sources/StateMachine.swift +++ b/Sources/StateMachine.swift @@ -546,14 +546,14 @@ public final class StateMachine: Machine infix operator <- : AdditionPrecedence @discardableResult -public func <- (machine: StateMachine, state: S) -> StateMachine +public func <- (machine: StateMachine, state: S) -> StateMachine { machine.tryState(state) return machine } @discardableResult -public func <- (machine: StateMachine, tuple: (S, Any?)) -> StateMachine +public func <- (machine: StateMachine, tuple: (S, Any?)) -> StateMachine { machine.tryState(tuple.0, userInfo: tuple.1) return machine diff --git a/Sources/StateType.swift b/Sources/StateType.swift index fc801a8..bf5e278 100644 --- a/Sources/StateType.swift +++ b/Sources/StateType.swift @@ -49,7 +49,7 @@ extension State: RawRepresentable } } -public func == (lhs: State, rhs: State) -> Bool +public func == (lhs: State, rhs: State) -> Bool { switch (lhs, rhs) { case let (.some(x1), .some(x2)) where x1 == x2: @@ -61,7 +61,7 @@ public func == (lhs: State, rhs: State) -> Bool } } -public func == (lhs: State, rhs: S) -> Bool +public func == (lhs: State, rhs: S) -> Bool { switch lhs { case .some(let x): @@ -71,7 +71,7 @@ public func == (lhs: State, rhs: S) -> Bool } } -public func == (lhs: S, rhs: State) -> Bool +public func == (lhs: S, rhs: State) -> Bool { switch rhs { case .some(let x): diff --git a/Sources/Transition.swift b/Sources/Transition.swift index 8827b81..0cba79d 100644 --- a/Sources/Transition.swift +++ b/Sources/Transition.swift @@ -43,7 +43,7 @@ public struct Transition: Hashable } // for Transition Equatable -public func == (left: Transition, right: Transition) -> Bool +public func == (left: Transition, right: Transition) -> Bool { return left.fromState == right.fromState && left.toState == right.toState } @@ -55,22 +55,22 @@ public func == (left: Transition, right: Transition) -> Bool infix operator => : AdditionPrecedence /// e.g. .state0 => .state1 -public func => (left: State, right: State) -> Transition +public func => (left: State, right: State) -> Transition { return Transition(fromState: left, toState: right) } -public func => (left: State, right: S) -> Transition +public func => (left: State, right: S) -> Transition { return left => .some(right) } -public func => (left: S, right: State) -> Transition +public func => (left: S, right: State) -> Transition { return .some(left) => right } -public func => (left: S, right: S) -> Transition +public func => (left: S, right: S) -> Transition { return .some(left) => .some(right) } diff --git a/Sources/TransitionChain.swift b/Sources/TransitionChain.swift index 76c77b6..c0fa93e 100644 --- a/Sources/TransitionChain.swift +++ b/Sources/TransitionChain.swift @@ -38,43 +38,43 @@ public struct TransitionChain //-------------------------------------------------- // e.g. (.state0 => .state1) => .state -public func => (left: Transition, right: State) -> TransitionChain +public func => (left: Transition, right: State) -> TransitionChain { return TransitionChain(states: [left.fromState, left.toState]) => right } -public func => (left: Transition, right: S) -> TransitionChain +public func => (left: Transition, right: S) -> TransitionChain { return left => .some(right) } -public func => (left: TransitionChain, right: State) -> TransitionChain +public func => (left: TransitionChain, right: State) -> TransitionChain { return TransitionChain(states: left.states + [right]) } -public func => (left: TransitionChain, right: S) -> TransitionChain +public func => (left: TransitionChain, right: S) -> TransitionChain { return left => .some(right) } // e.g. .state0 => (.state1 => .state) -public func => (left: State, right: Transition) -> TransitionChain +public func => (left: State, right: Transition) -> TransitionChain { return left => TransitionChain(states: [right.fromState, right.toState]) } -public func => (left: S, right: Transition) -> TransitionChain +public func => (left: S, right: Transition) -> TransitionChain { return .some(left) => right } -public func => (left: State, right: TransitionChain) -> TransitionChain +public func => (left: State, right: TransitionChain) -> TransitionChain { return TransitionChain(states: [left] + right.states) } -public func => (left: S, right: TransitionChain) -> TransitionChain +public func => (left: S, right: TransitionChain) -> TransitionChain { return .some(left) => right } diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index 3552690..bcd8b06 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -312,7 +312,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Yasuhiro Inami"; TargetAttributes = { 1FA61FFF1996601000460108 = { @@ -427,14 +427,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -475,14 +481,20 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; diff --git a/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme b/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme index 9e845a5..156778f 100644 --- a/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme +++ b/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme @@ -1,6 +1,6 @@ @@ -56,6 +57,7 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Tests/BasicTests.swift b/Tests/BasicTests.swift index 0aab84a..8f97c83 100644 --- a/Tests/BasicTests.swift +++ b/Tests/BasicTests.swift @@ -17,8 +17,8 @@ class BasicTests: _TestCase let machine = StateMachine(state: .state0) { machine in machine.addRoute(.state0 => .state1) - machine.addRoute(.any => .state2) { context in print("Any => 2, msg=\(context.userInfo)") } - machine.addRoute(.state2 => .any) { context in print("2 => Any, msg=\(context.userInfo)") } + machine.addRoute(.any => .state2) { context in print("Any => 2, msg=\(String(describing: context.userInfo))") } + machine.addRoute(.state2 => .any) { context in print("2 => Any, msg=\(String(describing: context.userInfo))") } // add handler (`context = (event, fromState, toState, userInfo)`) machine.addHandler(.state0 => .state1) { context in diff --git a/Tests/MiscTests.swift b/Tests/MiscTests.swift index 71ac2d5..7909237 100644 --- a/Tests/MiscTests.swift +++ b/Tests/MiscTests.swift @@ -17,8 +17,8 @@ class MiscTests: _TestCase let machine = StateMachine(state: ".State0") { machine in machine.addRoute(".State0" => ".State1") - machine.addRoute(.any => ".State2") { context in print("Any => 2, msg=\(context.userInfo)") } - machine.addRoute(".State2" => .any) { context in print("2 => Any, msg=\(context.userInfo)") } + machine.addRoute(.any => ".State2") { context in print("Any => 2, msg=\(String(describing: context.userInfo))") } + machine.addRoute(".State2" => .any) { context in print("2 => Any, msg=\(String(describing: context.userInfo))") } // add handler (handlerContext = (event, transition, order, userInfo)) machine.addHandler(".State0" => ".State1") { context in @@ -54,8 +54,8 @@ class MiscTests: _TestCase let machine = StateMachine(state: .str("0")) { machine in machine.addRoute(.str("0") => .str("1")) - machine.addRoute(.any => .str("2")) { context in print("Any => 2, msg=\(context.userInfo)") } - machine.addRoute(.str("2") => .any) { context in print("2 => Any, msg=\(context.userInfo)") } + machine.addRoute(.any => .str("2")) { context in print("Any => 2, msg=\(String(describing: context.userInfo))") } + machine.addRoute(.str("2") => .any) { context in print("2 => Any, msg=\(String(describing: context.userInfo))") } // add handler (handlerContext = (event, transition, order, userInfo)) machine.addHandler(.str("0") => .str("1")) { context in @@ -151,10 +151,10 @@ class MiscTests: _TestCase print("[Entry 1] \(context.fromState) => \(context.toState)") } $0.addHandler(.any => .state2) { context in - print("[Entry 2] \(context.fromState) => \(context.toState), userInfo = \(context.userInfo)") + print("[Entry 2] \(context.fromState) => \(context.toState), userInfo = \(String(describing: context.userInfo))") } $0.addHandler(.any => .state2) { context in - print("[Entry 2b] \(context.fromState) => \(context.toState), userInfo = \(context.userInfo)") + print("[Entry 2b] \(context.fromState) => \(context.toState), userInfo = \(String(describing: context.userInfo))") } // add exit handlers @@ -165,10 +165,10 @@ class MiscTests: _TestCase print("[Exit 1] \(context.fromState) => \(context.toState)") } $0.addHandler(.state2 => .any) { context in - print("[Exit 2] \(context.fromState) => \(context.toState), userInfo = \(context.userInfo)") + print("[Exit 2] \(context.fromState) => \(context.toState), userInfo = \(String(describing: context.userInfo))") } $0.addHandler(.state2 => .any) { context in - print("[Exit 2b] \(context.fromState) => \(context.toState), userInfo = \(context.userInfo)") + print("[Exit 2b] \(context.fromState) => \(context.toState), userInfo = \(String(describing: context.userInfo))") } } From d6d4d223dab665017052d42397886119d17df4cc Mon Sep 17 00:00:00 2001 From: Adam Yanalunas Date: Wed, 27 Sep 2017 15:16:33 -0700 Subject: [PATCH 02/20] Update project and code to Swift 4 --- Sources/Machine.swift | 12 ++++++------ Sources/StateMachine.swift | 14 +++++++------- SwiftState.xcodeproj/project.pbxproj | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/Machine.swift b/Sources/Machine.swift index 8d18824..80b7f7a 100644 --- a/Sources/Machine.swift +++ b/Sources/Machine.swift @@ -383,7 +383,7 @@ public class Machine // MARK: addRouteMapping + conditional handler @discardableResult - public func addRouteMapping(_ routeMapping: @escaping RouteMapping, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addRouteMapping(_ routeMapping: @escaping RouteMapping, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable { let routeDisposable = self.addRouteMapping(routeMapping) @@ -425,13 +425,13 @@ public class Machine // MARK: addHandler(event:) @discardableResult - public func addHandler(event: E, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addHandler(event: E, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable { return self.addHandler(event: .some(event), order: order, handler: handler) } @discardableResult - public func addHandler(event: Event, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addHandler(event: Event, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable { return self._addHandler(event: event, order: order) { context in // skip if not event-based transition @@ -446,7 +446,7 @@ public class Machine } @discardableResult - private func _addHandler(event: Event, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + private func _addHandler(event: Event, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { if self._handlers[event] == nil { self._handlers[event] = [] @@ -470,7 +470,7 @@ public class Machine // MARK: addErrorHandler @discardableResult - public func addErrorHandler(order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addErrorHandler(order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { let key = _createUniqueString() @@ -541,7 +541,7 @@ public func <-! (machine: Machine, tuple: (E, Any?)) -> Machine: Machine /// Add `handler` that is called when `tryState()` succeeds for target `transition`. /// - Note: `handler` will not be invoked for `tryEvent()`. @discardableResult - public func addHandler(_ transition: Transition, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addHandler(_ transition: Transition, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { if self._handlers[transition] == nil { self._handlers[transition] = [] @@ -322,7 +322,7 @@ public final class StateMachine: Machine /// Add `handler` that is called when either `tryEvent()` or `tryState()` succeeds for target `transition`. @discardableResult - public func addAnyHandler(_ transition: Transition, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addAnyHandler(_ transition: Transition, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { let disposable1 = self.addHandler(transition, order: order, handler: handler) let disposable2 = self.addHandler(event: .any, order: order) { context in @@ -372,13 +372,13 @@ public final class StateMachine: Machine // MARK: addChainHandler @discardableResult - public func addChainHandler(_ chain: TransitionChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addChainHandler(_ chain: TransitionChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { return self.addChainHandler(RouteChain(transitionChain: chain), order: order, handler: handler) } @discardableResult - public func addChainHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addChainHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { return self._addChainHandler(chain, order: order, handler: handler, isError: false) } @@ -386,19 +386,19 @@ public final class StateMachine: Machine // MARK: addChainErrorHandler @discardableResult - public func addChainErrorHandler(_ chain: TransitionChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addChainErrorHandler(_ chain: TransitionChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { return self.addChainErrorHandler(RouteChain(transitionChain: chain), order: order, handler: handler) } @discardableResult - public func addChainErrorHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable + public func addChainErrorHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable { return self._addChainHandler(chain, order: order, handler: handler, isError: true) } @discardableResult - private func _addChainHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler, isError: Bool) -> Disposable + private func _addChainHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler, isError: Bool) -> Disposable { var handlerDisposables: [Disposable] = [] diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index bcd8b06..a3f913f 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -317,11 +317,11 @@ TargetAttributes = { 1FA61FFF1996601000460108 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; 1FA6200A1996601000460108 = { CreatedOnToolsVersion = 6.0; - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -534,7 +534,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -554,7 +554,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -574,7 +574,7 @@ INFOPLIST_FILE = Tests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -590,7 +590,7 @@ INFOPLIST_FILE = Tests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; From 6347e6c35e3effe6a0d3626ef5d421090228cdf3 Mon Sep 17 00:00:00 2001 From: Adam Yanalunas Date: Wed, 27 Sep 2017 15:16:49 -0700 Subject: [PATCH 03/20] Update CircleCI to 4.0 branch --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6828e24..1751bff 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -SwiftState [![Circle CI](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F2.0.svg?style=svg)](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F2.0) +SwiftState [![Circle CI](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F4.0.svg?style=svg)](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F4.0) ========== Elegant state machine for Swift. From 2bdf6fabe831214d23055d1a7ee5608003befc11 Mon Sep 17 00:00:00 2001 From: Adam Yanalunas Date: Thu, 28 Sep 2017 18:44:28 -0700 Subject: [PATCH 04/20] Revert DefaultOrder property name to _defaultOrder --- Sources/Machine.swift | 12 ++++++------ Sources/StateMachine.swift | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/Sources/Machine.swift b/Sources/Machine.swift index 80b7f7a..ff22ab7 100644 --- a/Sources/Machine.swift +++ b/Sources/Machine.swift @@ -383,7 +383,7 @@ public class Machine // MARK: addRouteMapping + conditional handler @discardableResult - public func addRouteMapping(_ routeMapping: @escaping RouteMapping, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addRouteMapping(_ routeMapping: @escaping RouteMapping, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable { let routeDisposable = self.addRouteMapping(routeMapping) @@ -425,13 +425,13 @@ public class Machine // MARK: addHandler(event:) @discardableResult - public func addHandler(event: E, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addHandler(event: E, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable { return self.addHandler(event: .some(event), order: order, handler: handler) } @discardableResult - public func addHandler(event: Event, order: HandlerOrder = DefaultOrder, handler: @escaping Machine.Handler) -> Disposable + public func addHandler(event: Event, order: HandlerOrder = _defaultOrder, handler: @escaping Machine.Handler) -> Disposable { return self._addHandler(event: event, order: order) { context in // skip if not event-based transition @@ -446,7 +446,7 @@ public class Machine } @discardableResult - private func _addHandler(event: Event, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + private func _addHandler(event: Event, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { if self._handlers[event] == nil { self._handlers[event] = [] @@ -470,7 +470,7 @@ public class Machine // MARK: addErrorHandler @discardableResult - public func addErrorHandler(order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addErrorHandler(order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { let key = _createUniqueString() @@ -541,7 +541,7 @@ public func <-! (machine: Machine, tuple: (E, Any?)) -> Machine: Machine /// Add `handler` that is called when `tryState()` succeeds for target `transition`. /// - Note: `handler` will not be invoked for `tryEvent()`. @discardableResult - public func addHandler(_ transition: Transition, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addHandler(_ transition: Transition, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { if self._handlers[transition] == nil { self._handlers[transition] = [] @@ -322,7 +322,7 @@ public final class StateMachine: Machine /// Add `handler` that is called when either `tryEvent()` or `tryState()` succeeds for target `transition`. @discardableResult - public func addAnyHandler(_ transition: Transition, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addAnyHandler(_ transition: Transition, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { let disposable1 = self.addHandler(transition, order: order, handler: handler) let disposable2 = self.addHandler(event: .any, order: order) { context in @@ -372,13 +372,13 @@ public final class StateMachine: Machine // MARK: addChainHandler @discardableResult - public func addChainHandler(_ chain: TransitionChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addChainHandler(_ chain: TransitionChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { return self.addChainHandler(RouteChain(transitionChain: chain), order: order, handler: handler) } @discardableResult - public func addChainHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addChainHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { return self._addChainHandler(chain, order: order, handler: handler, isError: false) } @@ -386,19 +386,19 @@ public final class StateMachine: Machine // MARK: addChainErrorHandler @discardableResult - public func addChainErrorHandler(_ chain: TransitionChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addChainErrorHandler(_ chain: TransitionChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { return self.addChainErrorHandler(RouteChain(transitionChain: chain), order: order, handler: handler) } @discardableResult - public func addChainErrorHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler) -> Disposable + public func addChainErrorHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler) -> Disposable { return self._addChainHandler(chain, order: order, handler: handler, isError: true) } @discardableResult - private func _addChainHandler(_ chain: RouteChain, order: HandlerOrder = DefaultOrder, handler: @escaping Handler, isError: Bool) -> Disposable + private func _addChainHandler(_ chain: RouteChain, order: HandlerOrder = _defaultOrder, handler: @escaping Handler, isError: Bool) -> Disposable { var handlerDisposables: [Disposable] = [] From a986cb7c3b3ce3935d0043194f3c794ef3d03a03 Mon Sep 17 00:00:00 2001 From: Adam Yanalunas Date: Thu, 28 Sep 2017 18:44:41 -0700 Subject: [PATCH 05/20] Remove CircleCI badge from README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1751bff..590a353 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -SwiftState [![Circle CI](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F4.0.svg?style=svg)](https://circleci.com/gh/ReactKit/SwiftState/tree/swift%2F4.0) +SwiftState ========== Elegant state machine for Swift. From dbc9547624916952a76fa6cf4fc1f509da7ebf75 Mon Sep 17 00:00:00 2001 From: David Whetstone Date: Mon, 2 Apr 2018 15:11:54 -0700 Subject: [PATCH 06/20] Fix incorrect test path --- SwiftState.xcodeproj/project.pbxproj | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index bd7e074..643c163 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -236,7 +236,8 @@ 5243E3C71E9821E200D031A9 /* TransitionChainTests.swift */, 5243E3C81E9821E200D031A9 /* TransitionTests.swift */, ); - path = SwiftStateTests; + name = SwiftStateTests; + path = Tests/SwiftStateTests; sourceTree = ""; }; /* End PBXGroup section */ @@ -555,7 +556,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = SwiftStateTests/Info.plist; + INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; @@ -571,7 +572,7 @@ "$(DEVELOPER_FRAMEWORKS_DIR)", "$(inherited)", ); - INFOPLIST_FILE = SwiftStateTests/Info.plist; + INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_VERSION = 4.0; From bd79d8e50b0945df88c9a22ee6bddb0506df1e8c Mon Sep 17 00:00:00 2001 From: David Whetstone Date: Mon, 2 Apr 2018 15:29:27 -0700 Subject: [PATCH 07/20] Replace Machine.Context tuple with a struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allows Machine.Context to be extended. Tuples, as non-nominal types, can’t be extended. --- Sources/Machine.swift | 10 ++++++++-- Tests/SwiftStateTests/BasicTests.swift | 4 ++-- Tests/SwiftStateTests/HierarchicalMachineTests.swift | 8 ++++---- Tests/SwiftStateTests/MachineTests.swift | 2 +- Tests/SwiftStateTests/MiscTests.swift | 8 ++++---- Tests/SwiftStateTests/RouteMappingTests.swift | 4 ++-- 6 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Sources/Machine.swift b/Sources/Machine.swift index ff22ab7..23aa909 100644 --- a/Sources/Machine.swift +++ b/Sources/Machine.swift @@ -17,7 +17,13 @@ public class Machine { /// Closure argument for `Condition` & `Handler`. - public typealias Context = (event: E?, fromState: S, toState: S, userInfo: Any?) + public struct Context + { + public let event: E? + public let fromState: S + public let toState: S + public let userInfo: Any? + } /// Closure for validating transition. /// If condition returns `false`, transition will fail and associated handlers will not be invoked. @@ -569,7 +575,7 @@ internal func _validTransitions(fromState: S, toState: S) -> [Transition] internal func _canPassCondition(_ condition: Machine.Condition?, forEvent event: E?, fromState: S, toState: S, userInfo: Any?) -> Bool { - return condition?((event, fromState, toState, userInfo)) ?? true + return condition?(Machine.Context(event: event, fromState: fromState, toState: toState, userInfo: userInfo)) ?? true } internal func _insertHandlerIntoArray(_ handlerInfos: inout [_HandlerInfo], newHandlerInfo: _HandlerInfo) diff --git a/Tests/SwiftStateTests/BasicTests.swift b/Tests/SwiftStateTests/BasicTests.swift index 8f97c83..7dd88fa 100644 --- a/Tests/SwiftStateTests/BasicTests.swift +++ b/Tests/SwiftStateTests/BasicTests.swift @@ -26,8 +26,8 @@ class BasicTests: _TestCase } // add errorHandler - machine.addErrorHandler { event, fromState, toState, userInfo in - print("[ERROR] \(fromState) => \(toState)") + machine.addErrorHandler { context in + print("[ERROR] \(context.fromState) => \(context.toState)") } } diff --git a/Tests/SwiftStateTests/HierarchicalMachineTests.swift b/Tests/SwiftStateTests/HierarchicalMachineTests.swift index aa50914..ac6ab7a 100644 --- a/Tests/SwiftStateTests/HierarchicalMachineTests.swift +++ b/Tests/SwiftStateTests/HierarchicalMachineTests.swift @@ -92,9 +92,9 @@ class HierarchicalMachineTests: _TestCase let mainMachine = StateMachine<_MainState, NoEvent>(state: .mainState0) { mainMachine in // add routes & handle for same-subMachine internal transitions - mainMachine.addRoute(.any => .any, condition: { _, fromState, toState, userInfo in + mainMachine.addRoute(.any => .any, condition: { context in - switch (fromState, toState) { + switch (context.fromState, context.toState) { case let (.subMachine1(state1), .subMachine1(state2)): return subMachine1.hasRoute(fromState: state1, toState: state2) case let (.subMachine2(state1), .subMachine2(state2)): @@ -103,8 +103,8 @@ class HierarchicalMachineTests: _TestCase return false } - }, handler: { _, fromState, toState, userInfo in - switch (fromState, toState) { + }, handler: { context in + switch (context.fromState, context.toState) { case let (.subMachine1, .subMachine1(state2)): subMachine1 <- state2 case let (.subMachine2, .subMachine2(state2)): diff --git a/Tests/SwiftStateTests/MachineTests.swift b/Tests/SwiftStateTests/MachineTests.swift index 1414e19..3995481 100644 --- a/Tests/SwiftStateTests/MachineTests.swift +++ b/Tests/SwiftStateTests/MachineTests.swift @@ -341,7 +341,7 @@ class MachineTests: _TestCase let machine = Machine(state: .state0) { machine in machine.addRoutes(event: .event0, transitions: [ .state0 => .state1 ]) - machine.addErrorHandler { event, fromState, toState, userInfo in + machine.addErrorHandler { _ in invokeCount += 1 } } diff --git a/Tests/SwiftStateTests/MiscTests.swift b/Tests/SwiftStateTests/MiscTests.swift index 7909237..5b1fe90 100644 --- a/Tests/SwiftStateTests/MiscTests.swift +++ b/Tests/SwiftStateTests/MiscTests.swift @@ -26,8 +26,8 @@ class MiscTests: _TestCase } // add errorHandler - machine.addErrorHandler { event, fromState, toState, userInfo in - print("[ERROR] \(fromState) => \(toState)") + machine.addErrorHandler { context in + print("[ERROR] \(context.fromState) => \(context.toState)") } } @@ -63,8 +63,8 @@ class MiscTests: _TestCase } // add errorHandler - machine.addErrorHandler { event, fromState, toState, userInfo in - print("[ERROR] \(fromState) => \(toState)") + machine.addErrorHandler { context in + print("[ERROR] \(context.fromState) => \(context.toState)") } } diff --git a/Tests/SwiftStateTests/RouteMappingTests.swift b/Tests/SwiftStateTests/RouteMappingTests.swift index ddf765f..a0b8f38 100644 --- a/Tests/SwiftStateTests/RouteMappingTests.swift +++ b/Tests/SwiftStateTests/RouteMappingTests.swift @@ -98,7 +98,7 @@ class RouteMappingTests: _TestCase } // increment `count` when any events i.e. `.cancelAction` and `.loadAction(x)` succeed. - machine.addHandler(event: .any) { event, transition, order, userInfo in + machine.addHandler(event: .any) { _ in count += 1 } @@ -153,7 +153,7 @@ class RouteMappingTests: _TestCase } // increment `count` when any events i.e. `.cancelAction` and `.loadAction(x)` succeed. - machine.addHandler(.any => .any) { event, transition, order, userInfo in + machine.addHandler(.any => .any) { _ in count += 1 } From 28f4c2a4474c6fbb883ca932118414693e745d16 Mon Sep 17 00:00:00 2001 From: Amadeu Andrade Date: Wed, 4 Jul 2018 11:10:04 +0200 Subject: [PATCH 08/20] Bump version to 4.2.0 This adds the tag version and updates the podspec --- Sources/Info.plist | 2 +- SwiftState.podspec | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Info.plist b/Sources/Info.plist index 0cefffe..b237a65 100644 --- a/Sources/Info.plist +++ b/Sources/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 4.1.0 + 4.2.0 CFBundleSignature ???? CFBundleVersion diff --git a/SwiftState.podspec b/SwiftState.podspec index cb2cbdd..5ddbe9b 100644 --- a/SwiftState.podspec +++ b/SwiftState.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SwiftState' - s.version = '4.1.0' + s.version = '4.2.0' s.license = { :type => 'MIT' } s.homepage = 'https://github.com/ReactKit/SwiftState' s.authors = { 'Yasuhiro Inami' => 'inamiy@gmail.com' } From 327774759b0bde0251a7061343a2d2ef9ba07410 Mon Sep 17 00:00:00 2001 From: Konya Kirsten Date: Thu, 14 Mar 2019 09:36:47 +0100 Subject: [PATCH 09/20] Add Build Option 'Require Only App-Extension-Safe API' --- SwiftState.xcodeproj/project.pbxproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index 643c163..c9bd54a 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -507,6 +507,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 1FD79F971C1736D600CE7060 /* UniversalFramework_Framework.xcconfig */; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; @@ -527,6 +528,7 @@ isa = XCBuildConfiguration; baseConfigurationReference = 1FD79F971C1736D600CE7060 /* UniversalFramework_Framework.xcconfig */; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; From 917b3be9dcdfea4e962d7dd5ec869a7bbbfac5cd Mon Sep 17 00:00:00 2001 From: Emanuele Rudel Date: Sat, 15 Jun 2019 23:17:25 -0700 Subject: [PATCH 10/20] Update for Swift 5.0 --- Sources/EventType.swift | 3 +-- Sources/Transition.swift | 5 +++-- SwiftState.xcodeproj/project.pbxproj | 20 +++++++++++++------ .../xcschemes/SwiftState.xcscheme | 8 +++----- .../HierarchicalMachineTests.swift | 8 ++++---- Tests/SwiftStateTests/MyEvent.swift | 4 ++-- Tests/SwiftStateTests/MyState.swift | 4 ++-- Tests/SwiftStateTests/RouteMappingTests.swift | 12 +++++------ 8 files changed, 35 insertions(+), 29 deletions(-) diff --git a/Sources/EventType.swift b/Sources/EventType.swift index 7266065..b531f41 100644 --- a/Sources/EventType.swift +++ b/Sources/EventType.swift @@ -86,9 +86,8 @@ public func == (lhs: E, rhs: Event) -> Bool /// Useful for creating StateMachine without events, i.e. `StateMachine`. public enum NoEvent: EventType { - public var hashValue: Int + public func hash(into hasher: inout Hasher) { - return 0 } } diff --git a/Sources/Transition.swift b/Sources/Transition.swift index 0cba79d..445b183 100644 --- a/Sources/Transition.swift +++ b/Sources/Transition.swift @@ -36,9 +36,10 @@ public struct Transition: Hashable self.init(fromState: .some(fromState), toState: .some(toState)) } - public var hashValue: Int + public func hash(into hasher: inout Hasher) { - return self.fromState.hashValue &+ self.toState.hashValue.byteSwapped + hasher.combine(fromState.hashValue) + hasher.combine(toState.hashValue.byteSwapped) } } diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index 643c163..3e261d5 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -297,7 +297,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0900; + LastUpgradeCheck = 1020; ORGANIZATIONNAME = "Yasuhiro Inami"; TargetAttributes = { 1FA61FFF1996601000460108 = { @@ -312,10 +312,11 @@ }; buildConfigurationList = 1FA61FFA1996601000460108 /* Build configuration list for PBXProject "SwiftState" */; compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; + developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( en, + Base, ); mainGroup = 1FA61FF61996601000460108; productRefGroup = 1FA620011996601000460108 /* Products */; @@ -408,6 +409,7 @@ baseConfigurationReference = 1FD79FA51C17412600CE7060 /* Debug.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -416,12 +418,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -462,6 +466,7 @@ baseConfigurationReference = 1FD79FA61C17412600CE7060 /* Release.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; @@ -470,12 +475,14 @@ CLANG_WARN_BOOL_CONVERSION = YES; CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; @@ -498,6 +505,7 @@ GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; MTL_ENABLE_DEBUG_INFO = NO; + SWIFT_COMPILATION_MODE = wholemodule; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -519,7 +527,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -539,7 +547,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -559,7 +567,7 @@ INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -575,7 +583,7 @@ INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 4.0; + SWIFT_VERSION = 5.0; }; name = Release; }; diff --git a/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme b/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme index 156778f..49e1b54 100644 --- a/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme +++ b/SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme @@ -1,6 +1,6 @@ + codeCoverageEnabled = "YES" + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -57,7 +56,6 @@ buildConfiguration = "Debug" selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" - language = "" launchStyle = "0" useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" diff --git a/Tests/SwiftStateTests/HierarchicalMachineTests.swift b/Tests/SwiftStateTests/HierarchicalMachineTests.swift index ac6ab7a..aa18eba 100644 --- a/Tests/SwiftStateTests/HierarchicalMachineTests.swift +++ b/Tests/SwiftStateTests/HierarchicalMachineTests.swift @@ -15,15 +15,15 @@ private enum _MainState: StateType case subMachine1(_SubState) case subMachine2(_SubState) - var hashValue: Int + func hash(into hasher: inout Hasher) { switch self { case .mainState0: - return "MainState0".hashValue + hasher.combine("MainState0".hashValue) case let .subMachine1(state): - return "SubMachine1-\(state)".hashValue + hasher.combine("SubMachine1-\(state)".hashValue) case let .subMachine2(state): - return "SubMachine2-\(state)".hashValue + hasher.combine("SubMachine2-\(state)".hashValue) } } } diff --git a/Tests/SwiftStateTests/MyEvent.swift b/Tests/SwiftStateTests/MyEvent.swift index bf86a3a..563a78a 100644 --- a/Tests/SwiftStateTests/MyEvent.swift +++ b/Tests/SwiftStateTests/MyEvent.swift @@ -17,10 +17,10 @@ enum StrEvent: EventType { case str(String) - var hashValue: Int + func hash(into hasher: inout Hasher) { switch self { - case .str(let str): return str.hashValue + case .str(let str): hasher.combine(str.hashValue) } } } diff --git a/Tests/SwiftStateTests/MyState.swift b/Tests/SwiftStateTests/MyState.swift index b1cc1db..7425bb6 100644 --- a/Tests/SwiftStateTests/MyState.swift +++ b/Tests/SwiftStateTests/MyState.swift @@ -17,10 +17,10 @@ enum StrState: StateType { case str(String) - var hashValue: Int + func hash(into hasher: inout Hasher) { switch self { - case .str(let str): return str.hashValue + case .str(let str): hasher.combine(str.hashValue) } } } diff --git a/Tests/SwiftStateTests/RouteMappingTests.swift b/Tests/SwiftStateTests/RouteMappingTests.swift index a0b8f38..a92ed06 100644 --- a/Tests/SwiftStateTests/RouteMappingTests.swift +++ b/Tests/SwiftStateTests/RouteMappingTests.swift @@ -21,13 +21,13 @@ private enum _State: StateType, Hashable case pending case loading(Int) - var hashValue: Int + func hash(into hasher: inout Hasher) { switch self { case .pending: - return "Pending".hashValue + hasher.combine("Pending".hashValue) case let .loading(x): - return "Loading\(x)".hashValue + hasher.combine("Loading\(x)".hashValue) } } } @@ -49,13 +49,13 @@ private enum _Event: SwiftState.EventType, Hashable case cancelAction case loadAction(Int) - var hashValue: Int + func hash(into hasher: inout Hasher) { switch self { case .cancelAction: - return "CancelAction".hashValue + hasher.combine("CancelAction".hashValue) case let .loadAction(x): - return "LoadAction\(x)".hashValue + hasher.combine("LoadAction\(x)".hashValue) } } } From 9f4c19aafcde4ab4725ed09cc544d03e559b63a6 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Mon, 17 Jun 2019 01:51:30 +0900 Subject: [PATCH 11/20] [Xcode] Add IDEWorkspaceChecks.plist --- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 SwiftState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/SwiftState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/SwiftState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/SwiftState.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + From 1c53ce12ca939bae2b329196d24a3b636acca3e3 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Mon, 17 Jun 2019 01:51:42 +0900 Subject: [PATCH 12/20] Update podspec --- SwiftState.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftState.podspec b/SwiftState.podspec index 5ddbe9b..b527f04 100644 --- a/SwiftState.podspec +++ b/SwiftState.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SwiftState' - s.version = '4.2.0' + s.version = '5.0.0' s.license = { :type => 'MIT' } s.homepage = 'https://github.com/ReactKit/SwiftState' s.authors = { 'Yasuhiro Inami' => 'inamiy@gmail.com' } From e7f32fd6ab2386a317f439b6385f2dabd6db4fb7 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Mon, 17 Jun 2019 02:03:27 +0900 Subject: [PATCH 13/20] Update xcconfig --- Configurations/Base.xcconfig | 4 +++- SwiftState.xcodeproj/project.pbxproj | 4 ---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/Configurations/Base.xcconfig b/Configurations/Base.xcconfig index a8a1138..522fbff 100644 --- a/Configurations/Base.xcconfig +++ b/Configurations/Base.xcconfig @@ -10,4 +10,6 @@ CODE_SIGN_IDENTITY[sdk=iphoneos*] = iPhone Developer; MACOSX_DEPLOYMENT_TARGET = 10.9; IPHONEOS_DEPLOYMENT_TARGET = 8.0; WATCHOS_DEPLOYMENT_TARGET = 2.0; -TVOS_DEPLOYMENT_TARGET = 9.0; \ No newline at end of file +TVOS_DEPLOYMENT_TARGET = 9.0; + +SWIFT_VERSION = 5.0 diff --git a/SwiftState.xcodeproj/project.pbxproj b/SwiftState.xcodeproj/project.pbxproj index 66629a2..a8453b6 100644 --- a/SwiftState.xcodeproj/project.pbxproj +++ b/SwiftState.xcodeproj/project.pbxproj @@ -528,7 +528,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -549,7 +548,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 5.0; }; name = Release; }; @@ -569,7 +567,6 @@ INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -585,7 +582,6 @@ INFOPLIST_FILE = Tests/SwiftStateTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 5.0; }; name = Release; }; From 8cb92f38ccf34a8b3aa81c5c5cd90ebddaa976f8 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Mon, 17 Jun 2019 02:03:54 +0900 Subject: [PATCH 14/20] Update podspec --- SwiftState.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftState.podspec b/SwiftState.podspec index b527f04..5443b3b 100644 --- a/SwiftState.podspec +++ b/SwiftState.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SwiftState' - s.version = '5.0.0' + s.version = '6.0.0' s.license = { :type => 'MIT' } s.homepage = 'https://github.com/ReactKit/SwiftState' s.authors = { 'Yasuhiro Inami' => 'inamiy@gmail.com' } From fbc36eab93a59a368e5f24a3b4902f1b941b1d39 Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 18:37:11 +0530 Subject: [PATCH 15/20] spm support --- Package.swift | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Package.swift b/Package.swift index f0b256b..1fd0a49 100644 --- a/Package.swift +++ b/Package.swift @@ -10,4 +10,12 @@ import PackageDescription let package = Package( name: "SwiftState" + name: "SwiftState", + platforms: [.iOS(.v11),.watchOS(*)], + products: [ + .library(name: "SwiftState", targets: ["SwiftState"]) + ], + targets: [ + .target(name: "SwiftState", path: "Sources") + ] ) From 1c5b64de18cc44561c4061b885dcb3c6da5af558 Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 18:42:53 +0530 Subject: [PATCH 16/20] compiler error fix --- Package.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Package.swift b/Package.swift index 1fd0a49..ebc1a95 100644 --- a/Package.swift +++ b/Package.swift @@ -9,7 +9,6 @@ import PackageDescription let package = Package( - name: "SwiftState" name: "SwiftState", platforms: [.iOS(.v11),.watchOS(*)], products: [ From 9f3f97b9e065d9cc9f6d29d40ff6e6a7ae82e157 Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 18:47:36 +0530 Subject: [PATCH 17/20] swift package manager support --- Package.swift | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index ebc1a95..b4f6daa 100644 --- a/Package.swift +++ b/Package.swift @@ -1,20 +1,28 @@ -// -// Package.swift -// SwiftState -// -// Created by Yasuhiro Inami on 2015-12-05. -// Copyright © 2015 Yasuhiro Inami. All rights reserved. -// +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package( name: "SwiftState", - platforms: [.iOS(.v11),.watchOS(*)], products: [ - .library(name: "SwiftState", targets: ["SwiftState"]) + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "SwiftState", + targets: ["SwiftState"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), ], targets: [ - .target(name: "SwiftState", path: "Sources") + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "SwiftState", + dependencies: []), + .testTarget( + name: "SwiftStateTests", + dependencies: ["SwiftState"]), ] ) From 3a49bb88f58b764ff2b2db42146fade2ff683dd8 Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 18:53:10 +0530 Subject: [PATCH 18/20] Attempt to fix spm issue --- Sources/{_HandlerID.swift => HandlerID.swift} | 0 Sources/{_HandlerInfo.swift => HandlerInfo.swift} | 0 Sources/{_Random.swift => Random.swift} | 0 Sources/{_RouteID.swift => RouteID.swift} | 0 Sources/{_RouteMappingID.swift => RouteMappingID.swift} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename Sources/{_HandlerID.swift => HandlerID.swift} (100%) rename Sources/{_HandlerInfo.swift => HandlerInfo.swift} (100%) rename Sources/{_Random.swift => Random.swift} (100%) rename Sources/{_RouteID.swift => RouteID.swift} (100%) rename Sources/{_RouteMappingID.swift => RouteMappingID.swift} (100%) diff --git a/Sources/_HandlerID.swift b/Sources/HandlerID.swift similarity index 100% rename from Sources/_HandlerID.swift rename to Sources/HandlerID.swift diff --git a/Sources/_HandlerInfo.swift b/Sources/HandlerInfo.swift similarity index 100% rename from Sources/_HandlerInfo.swift rename to Sources/HandlerInfo.swift diff --git a/Sources/_Random.swift b/Sources/Random.swift similarity index 100% rename from Sources/_Random.swift rename to Sources/Random.swift diff --git a/Sources/_RouteID.swift b/Sources/RouteID.swift similarity index 100% rename from Sources/_RouteID.swift rename to Sources/RouteID.swift diff --git a/Sources/_RouteMappingID.swift b/Sources/RouteMappingID.swift similarity index 100% rename from Sources/_RouteMappingID.swift rename to Sources/RouteMappingID.swift From 84886b8259b9a093d8445abf39c91f6461c6ad32 Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 19:01:31 +0530 Subject: [PATCH 19/20] update --- Sources/{HandlerID.swift => _HandlerID.swift} | 0 Sources/{HandlerInfo.swift => _HandlerInfo.swift} | 0 Sources/{Random.swift => _Random.swift} | 0 Sources/{RouteID.swift => _RouteID.swift} | 0 Sources/{RouteMappingID.swift => _RouteMappingID.swift} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename Sources/{HandlerID.swift => _HandlerID.swift} (100%) rename Sources/{HandlerInfo.swift => _HandlerInfo.swift} (100%) rename Sources/{Random.swift => _Random.swift} (100%) rename Sources/{RouteID.swift => _RouteID.swift} (100%) rename Sources/{RouteMappingID.swift => _RouteMappingID.swift} (100%) diff --git a/Sources/HandlerID.swift b/Sources/_HandlerID.swift similarity index 100% rename from Sources/HandlerID.swift rename to Sources/_HandlerID.swift diff --git a/Sources/HandlerInfo.swift b/Sources/_HandlerInfo.swift similarity index 100% rename from Sources/HandlerInfo.swift rename to Sources/_HandlerInfo.swift diff --git a/Sources/Random.swift b/Sources/_Random.swift similarity index 100% rename from Sources/Random.swift rename to Sources/_Random.swift diff --git a/Sources/RouteID.swift b/Sources/_RouteID.swift similarity index 100% rename from Sources/RouteID.swift rename to Sources/_RouteID.swift diff --git a/Sources/RouteMappingID.swift b/Sources/_RouteMappingID.swift similarity index 100% rename from Sources/RouteMappingID.swift rename to Sources/_RouteMappingID.swift From 43aa9c04d60b0be5d3140f0e8a23e6670371f51b Mon Sep 17 00:00:00 2001 From: Srinivas Prabhu Date: Tue, 8 Dec 2020 19:07:26 +0530 Subject: [PATCH 20/20] Updated source path in spm file --- Package.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Package.swift b/Package.swift index b4f6daa..8c11573 100644 --- a/Package.swift +++ b/Package.swift @@ -20,9 +20,11 @@ let package = Package( // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( name: "SwiftState", - dependencies: []), + dependencies: [], + path:"Sources"), .testTarget( name: "SwiftStateTests", - dependencies: ["SwiftState"]), + dependencies: ["SwiftState"], + path:"Sources"), ] )