Skip to content

Commit 64d56f5

Browse files
authored
Merge pull request #59 from adamyanalunas/swift/4.0
Swift 4.0 support
2 parents abeb139 + a986cb7 commit 64d56f5

File tree

12 files changed

+66
-52
lines changed

12 files changed

+66
-52
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
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)
1+
SwiftState
22
==========
33

44
Elegant state machine for Swift.

Sources/EventType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension Event: RawRepresentable
4949
}
5050
}
5151

52-
public func == <E: EventType>(lhs: Event<E>, rhs: Event<E>) -> Bool
52+
public func == <E>(lhs: Event<E>, rhs: Event<E>) -> Bool
5353
{
5454
switch (lhs, rhs) {
5555
case let (.some(x1), .some(x2)) where x1 == x2:
@@ -61,7 +61,7 @@ public func == <E: EventType>(lhs: Event<E>, rhs: Event<E>) -> Bool
6161
}
6262
}
6363

64-
public func == <E: EventType>(lhs: Event<E>, rhs: E) -> Bool
64+
public func == <E>(lhs: Event<E>, rhs: E) -> Bool
6565
{
6666
switch lhs {
6767
case .some(let x):
@@ -71,7 +71,7 @@ public func == <E: EventType>(lhs: Event<E>, rhs: E) -> Bool
7171
}
7272
}
7373

74-
public func == <E: EventType>(lhs: E, rhs: Event<E>) -> Bool
74+
public func == <E>(lhs: E, rhs: Event<E>) -> Bool
7575
{
7676
switch rhs {
7777
case .some(let x):

Sources/Machine.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -521,14 +521,14 @@ public class Machine<S: StateType, E: EventType>
521521
infix operator <-! : AdditionPrecedence
522522

523523
@discardableResult
524-
public func <-! <S: StateType, E: EventType>(machine: Machine<S, E>, event: E) -> Machine<S, E>
524+
public func <-! <S, E>(machine: Machine<S, E>, event: E) -> Machine<S, E>
525525
{
526526
machine.tryEvent(event)
527527
return machine
528528
}
529529

530530
@discardableResult
531-
public func <-! <S: StateType, E: EventType>(machine: Machine<S, E>, tuple: (E, Any?)) -> Machine<S, E>
531+
public func <-! <S, E>(machine: Machine<S, E>, tuple: (E, Any?)) -> Machine<S, E>
532532
{
533533
machine.tryEvent(tuple.0, userInfo: tuple.1)
534534
return machine
@@ -541,7 +541,7 @@ public func <-! <S: StateType, E: EventType>(machine: Machine<S, E>, tuple: (E,
541541
/// Precedence for registered handlers (higher number is called later).
542542
public typealias HandlerOrder = UInt8
543543

544-
internal let _defaultOrder: HandlerOrder = 100
544+
public let _defaultOrder: HandlerOrder = 100
545545

546546
//--------------------------------------------------
547547
// MARK: - Internal
@@ -557,7 +557,7 @@ internal func _createUniqueString() -> String
557557
return uniqueString
558558
}
559559

560-
internal func _validTransitions<S: StateType>(fromState: S, toState: S) -> [Transition<S>]
560+
internal func _validTransitions<S>(fromState: S, toState: S) -> [Transition<S>]
561561
{
562562
return [
563563
fromState => toState,
@@ -567,12 +567,12 @@ internal func _validTransitions<S: StateType>(fromState: S, toState: S) -> [Tran
567567
]
568568
}
569569

570-
internal func _canPassCondition<S: StateType, E: EventType>(_ condition: Machine<S, E>.Condition?, forEvent event: E?, fromState: S, toState: S, userInfo: Any?) -> Bool
570+
internal func _canPassCondition<S:StateType, E:EventType>(_ condition: Machine<S, E>.Condition?, forEvent event: E?, fromState: S, toState: S, userInfo: Any?) -> Bool
571571
{
572572
return condition?((event, fromState, toState, userInfo)) ?? true
573573
}
574574

575-
internal func _insertHandlerIntoArray<S: StateType, E: EventType>(_ handlerInfos: inout [_HandlerInfo<S, E>], newHandlerInfo: _HandlerInfo<S, E>)
575+
internal func _insertHandlerIntoArray<S, E>(_ handlerInfos: inout [_HandlerInfo<S, E>], newHandlerInfo: _HandlerInfo<S, E>)
576576
{
577577
var index = handlerInfos.count
578578

@@ -586,7 +586,7 @@ internal func _insertHandlerIntoArray<S: StateType, E: EventType>(_ handlerInfos
586586
handlerInfos.insert(newHandlerInfo, at: index)
587587
}
588588

589-
internal func _removeHandlerFromArray<S: StateType, E: EventType>(_ handlerInfos: inout [_HandlerInfo<S, E>], removingHandlerID: _HandlerID<S, E>) -> Bool
589+
internal func _removeHandlerFromArray<S, E>(_ handlerInfos: inout [_HandlerInfo<S, E>], removingHandlerID: _HandlerID<S, E>) -> Bool
590590
{
591591
for i in 0..<handlerInfos.count {
592592
if handlerInfos[i].key == removingHandlerID.key {

Sources/Route.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,34 @@ public struct Route<S: StateType, E: EventType>
2424
//--------------------------------------------------
2525

2626
/// e.g. [.state0, .state1] => .state, allowing [0 => 2, 1 => 2]
27-
public func => <S: StateType, E: EventType>(leftStates: [S], right: State<S>) -> Route<S, E>
27+
public func => <S, E>(leftStates: [S], right: State<S>) -> Route<S, E>
2828
{
2929
// NOTE: don't reuse ".any => .any + condition" for efficiency
3030
return Route(transition: .any => right, condition: { context -> Bool in
3131
return leftStates.contains(context.fromState)
3232
})
3333
}
3434

35-
public func => <S: StateType, E: EventType>(leftStates: [S], right: S) -> Route<S, E>
35+
public func => <S, E>(leftStates: [S], right: S) -> Route<S, E>
3636
{
3737
return leftStates => .some(right)
3838
}
3939

4040
/// e.g. .state0 => [.state1, .state], allowing [0 => 1, 0 => 2]
41-
public func => <S: StateType, E: EventType>(left: State<S>, rightStates: [S]) -> Route<S, E>
41+
public func => <S, E>(left: State<S>, rightStates: [S]) -> Route<S, E>
4242
{
4343
return Route(transition: left => .any, condition: { context -> Bool in
4444
return rightStates.contains(context.toState)
4545
})
4646
}
4747

48-
public func => <S: StateType, E: EventType>(left: S, rightStates: [S]) -> Route<S, E>
48+
public func => <S, E>(left: S, rightStates: [S]) -> Route<S, E>
4949
{
5050
return .some(left) => rightStates
5151
}
5252

5353
/// e.g. [.state0, .state1] => [.state, .state3], allowing [0 => 2, 0 => 3, 1 => 2, 1 => 3]
54-
public func => <S: StateType, E: EventType>(leftStates: [S], rightStates: [S]) -> Route<S, E>
54+
public func => <S, E>(leftStates: [S], rightStates: [S]) -> Route<S, E>
5555
{
5656
return Route(transition: .any => .any, condition: { context -> Bool in
5757
return leftStates.contains(context.fromState) && rightStates.contains(context.toState)

Sources/StateMachine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,14 +546,14 @@ public final class StateMachine<S: StateType, E: EventType>: Machine<S, E>
546546
infix operator <- : AdditionPrecedence
547547

548548
@discardableResult
549-
public func <- <S: StateType, E: EventType>(machine: StateMachine<S, E>, state: S) -> StateMachine<S, E>
549+
public func <- <S, E>(machine: StateMachine<S, E>, state: S) -> StateMachine<S, E>
550550
{
551551
machine.tryState(state)
552552
return machine
553553
}
554554

555555
@discardableResult
556-
public func <- <S: StateType, E: EventType>(machine: StateMachine<S, E>, tuple: (S, Any?)) -> StateMachine<S, E>
556+
public func <- <S, E>(machine: StateMachine<S, E>, tuple: (S, Any?)) -> StateMachine<S, E>
557557
{
558558
machine.tryState(tuple.0, userInfo: tuple.1)
559559
return machine

Sources/StateType.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension State: RawRepresentable
4949
}
5050
}
5151

52-
public func == <S: StateType>(lhs: State<S>, rhs: State<S>) -> Bool
52+
public func == <S>(lhs: State<S>, rhs: State<S>) -> Bool
5353
{
5454
switch (lhs, rhs) {
5555
case let (.some(x1), .some(x2)) where x1 == x2:
@@ -61,7 +61,7 @@ public func == <S: StateType>(lhs: State<S>, rhs: State<S>) -> Bool
6161
}
6262
}
6363

64-
public func == <S: StateType>(lhs: State<S>, rhs: S) -> Bool
64+
public func == <S>(lhs: State<S>, rhs: S) -> Bool
6565
{
6666
switch lhs {
6767
case .some(let x):
@@ -71,7 +71,7 @@ public func == <S: StateType>(lhs: State<S>, rhs: S) -> Bool
7171
}
7272
}
7373

74-
public func == <S: StateType>(lhs: S, rhs: State<S>) -> Bool
74+
public func == <S>(lhs: S, rhs: State<S>) -> Bool
7575
{
7676
switch rhs {
7777
case .some(let x):

Sources/Transition.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public struct Transition<S: StateType>: Hashable
4343
}
4444

4545
// for Transition Equatable
46-
public func == <S: StateType>(left: Transition<S>, right: Transition<S>) -> Bool
46+
public func == <S>(left: Transition<S>, right: Transition<S>) -> Bool
4747
{
4848
return left.fromState == right.fromState && left.toState == right.toState
4949
}
@@ -55,22 +55,22 @@ public func == <S: StateType>(left: Transition<S>, right: Transition<S>) -> Bool
5555
infix operator => : AdditionPrecedence
5656

5757
/// e.g. .state0 => .state1
58-
public func => <S: StateType>(left: State<S>, right: State<S>) -> Transition<S>
58+
public func => <S>(left: State<S>, right: State<S>) -> Transition<S>
5959
{
6060
return Transition(fromState: left, toState: right)
6161
}
6262

63-
public func => <S: StateType>(left: State<S>, right: S) -> Transition<S>
63+
public func => <S>(left: State<S>, right: S) -> Transition<S>
6464
{
6565
return left => .some(right)
6666
}
6767

68-
public func => <S: StateType>(left: S, right: State<S>) -> Transition<S>
68+
public func => <S>(left: S, right: State<S>) -> Transition<S>
6969
{
7070
return .some(left) => right
7171
}
7272

73-
public func => <S: StateType>(left: S, right: S) -> Transition<S>
73+
public func => <S>(left: S, right: S) -> Transition<S>
7474
{
7575
return .some(left) => .some(right)
7676
}

Sources/TransitionChain.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,43 @@ public struct TransitionChain<S: StateType>
3838
//--------------------------------------------------
3939

4040
// e.g. (.state0 => .state1) => .state
41-
public func => <S: StateType>(left: Transition<S>, right: State<S>) -> TransitionChain<S>
41+
public func => <S>(left: Transition<S>, right: State<S>) -> TransitionChain<S>
4242
{
4343
return TransitionChain(states: [left.fromState, left.toState]) => right
4444
}
4545

46-
public func => <S: StateType>(left: Transition<S>, right: S) -> TransitionChain<S>
46+
public func => <S>(left: Transition<S>, right: S) -> TransitionChain<S>
4747
{
4848
return left => .some(right)
4949
}
5050

51-
public func => <S: StateType>(left: TransitionChain<S>, right: State<S>) -> TransitionChain<S>
51+
public func => <S>(left: TransitionChain<S>, right: State<S>) -> TransitionChain<S>
5252
{
5353
return TransitionChain(states: left.states + [right])
5454
}
5555

56-
public func => <S: StateType>(left: TransitionChain<S>, right: S) -> TransitionChain<S>
56+
public func => <S>(left: TransitionChain<S>, right: S) -> TransitionChain<S>
5757
{
5858
return left => .some(right)
5959
}
6060

6161
// e.g. .state0 => (.state1 => .state)
62-
public func => <S: StateType>(left: State<S>, right: Transition<S>) -> TransitionChain<S>
62+
public func => <S>(left: State<S>, right: Transition<S>) -> TransitionChain<S>
6363
{
6464
return left => TransitionChain(states: [right.fromState, right.toState])
6565
}
6666

67-
public func => <S: StateType>(left: S, right: Transition<S>) -> TransitionChain<S>
67+
public func => <S>(left: S, right: Transition<S>) -> TransitionChain<S>
6868
{
6969
return .some(left) => right
7070
}
7171

72-
public func => <S: StateType>(left: State<S>, right: TransitionChain<S>) -> TransitionChain<S>
72+
public func => <S>(left: State<S>, right: TransitionChain<S>) -> TransitionChain<S>
7373
{
7474
return TransitionChain(states: [left] + right.states)
7575
}
7676

77-
public func => <S: StateType>(left: S, right: TransitionChain<S>) -> TransitionChain<S>
77+
public func => <S>(left: S, right: TransitionChain<S>) -> TransitionChain<S>
7878
{
7979
return .some(left) => right
8080
}

SwiftState.xcodeproj/project.pbxproj

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -312,16 +312,16 @@
312312
isa = PBXProject;
313313
attributes = {
314314
LastSwiftUpdateCheck = 0700;
315-
LastUpgradeCheck = 0800;
315+
LastUpgradeCheck = 0900;
316316
ORGANIZATIONNAME = "Yasuhiro Inami";
317317
TargetAttributes = {
318318
1FA61FFF1996601000460108 = {
319319
CreatedOnToolsVersion = 6.0;
320-
LastSwiftMigration = 0800;
320+
LastSwiftMigration = 0900;
321321
};
322322
1FA6200A1996601000460108 = {
323323
CreatedOnToolsVersion = 6.0;
324-
LastSwiftMigration = 0800;
324+
LastSwiftMigration = 0900;
325325
};
326326
};
327327
};
@@ -427,14 +427,20 @@
427427
CLANG_CXX_LIBRARY = "libc++";
428428
CLANG_ENABLE_MODULES = YES;
429429
CLANG_ENABLE_OBJC_ARC = YES;
430+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
430431
CLANG_WARN_BOOL_CONVERSION = YES;
432+
CLANG_WARN_COMMA = YES;
431433
CLANG_WARN_CONSTANT_CONVERSION = YES;
432434
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
433435
CLANG_WARN_EMPTY_BODY = YES;
434436
CLANG_WARN_ENUM_CONVERSION = YES;
435437
CLANG_WARN_INFINITE_RECURSION = YES;
436438
CLANG_WARN_INT_CONVERSION = YES;
439+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
440+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
437441
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
442+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
443+
CLANG_WARN_STRICT_PROTOTYPES = YES;
438444
CLANG_WARN_SUSPICIOUS_MOVE = YES;
439445
CLANG_WARN_UNREACHABLE_CODE = YES;
440446
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -475,14 +481,20 @@
475481
CLANG_CXX_LIBRARY = "libc++";
476482
CLANG_ENABLE_MODULES = YES;
477483
CLANG_ENABLE_OBJC_ARC = YES;
484+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
478485
CLANG_WARN_BOOL_CONVERSION = YES;
486+
CLANG_WARN_COMMA = YES;
479487
CLANG_WARN_CONSTANT_CONVERSION = YES;
480488
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
481489
CLANG_WARN_EMPTY_BODY = YES;
482490
CLANG_WARN_ENUM_CONVERSION = YES;
483491
CLANG_WARN_INFINITE_RECURSION = YES;
484492
CLANG_WARN_INT_CONVERSION = YES;
493+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
494+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
485495
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
496+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
497+
CLANG_WARN_STRICT_PROTOTYPES = YES;
486498
CLANG_WARN_SUSPICIOUS_MOVE = YES;
487499
CLANG_WARN_UNREACHABLE_CODE = YES;
488500
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
@@ -522,7 +534,7 @@
522534
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
523535
PRODUCT_NAME = "$(PROJECT_NAME)";
524536
SKIP_INSTALL = YES;
525-
SWIFT_VERSION = 3.0;
537+
SWIFT_VERSION = 4.0;
526538
};
527539
name = Debug;
528540
};
@@ -542,7 +554,7 @@
542554
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
543555
PRODUCT_NAME = "$(PROJECT_NAME)";
544556
SKIP_INSTALL = YES;
545-
SWIFT_VERSION = 3.0;
557+
SWIFT_VERSION = 4.0;
546558
};
547559
name = Release;
548560
};
@@ -562,7 +574,7 @@
562574
INFOPLIST_FILE = Tests/Info.plist;
563575
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
564576
PRODUCT_NAME = "$(TARGET_NAME)";
565-
SWIFT_VERSION = 3.0;
577+
SWIFT_VERSION = 4.0;
566578
};
567579
name = Debug;
568580
};
@@ -578,7 +590,7 @@
578590
INFOPLIST_FILE = Tests/Info.plist;
579591
PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)";
580592
PRODUCT_NAME = "$(TARGET_NAME)";
581-
SWIFT_VERSION = 3.0;
593+
SWIFT_VERSION = 4.0;
582594
};
583595
name = Release;
584596
};

SwiftState.xcodeproj/xcshareddata/xcschemes/SwiftState.xcscheme

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES"
3031
codeCoverageEnabled = "YES">
3132
<Testables>
@@ -56,6 +57,7 @@
5657
buildConfiguration = "Debug"
5758
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5859
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
60+
language = ""
5961
launchStyle = "0"
6062
useCustomWorkingDirectory = "NO"
6163
ignoresPersistentStateOnLaunch = "NO"

0 commit comments

Comments
 (0)