Skip to content

Commit 1792bfc

Browse files
committed
Completes swift 5 migration
1 parent 6b32bca commit 1792bfc

File tree

6 files changed

+26
-42
lines changed

6 files changed

+26
-42
lines changed

Source/Promise+Chain.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
public extension Promise {
1212

13-
public func chain(_ block:@escaping (T) -> Void) -> Promise<T> {
13+
func chain(_ block:@escaping (T) -> Void) -> Promise<T> {
1414
let p = newLinkedPromise()
1515
syncStateWithCallBacks(success: { t in
1616
block(t)

Source/Promise+Delay.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ extension Promise {
2727

2828
extension Promises {
2929
public static func delay(_ time: TimeInterval) -> Promise<Void> {
30-
return Promise { (resolve: @escaping ((()) -> Void), _: @escaping ((Error) -> Void)) in
31-
let erasedResolve = { resolve(()) }
32-
callBackOnCallingQueueIn(time: time, block: erasedResolve)
30+
return Promise { (resolve: @escaping (() -> Void), _: @escaping ((Error) -> Void)) in
31+
callBackOnCallingQueueIn(time: time, block: resolve)
3332
}
3433
}
3534
}

Source/Promise+Helpers.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,7 @@ public extension Promise {
2222

2323
extension Promise where T == Void {
2424
public class func resolve() -> Promise<Void> {
25-
26-
let callback: ((_ resolve: @escaping ((()) -> Void), _ reject: @escaping ((Error) -> Void)) -> Void)
27-
= { resolve, reject in resolve(()) }
28-
29-
return Promise.init(callback: callback)
30-
25+
return Promise { resolve, _ in resolve() }
3126
}
3227
}
3328

Source/VoidPromise.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ import Foundation
1111
extension Promise where T == Void {
1212

1313
public convenience init(callback: @escaping (
14-
_ resolve: @escaping ((()) -> Void),
14+
_ resolve: @escaping (() -> Void),
1515
_ reject: @escaping ((Error) -> Void)) -> Void) {
1616
self.init()
1717
setProgressCallBack { resolve, reject, _ in
18-
callback(resolve, reject)
18+
let wrapped = { resolve(()) }
19+
callback(wrapped, reject)
1920
}
2021
}
2122

2223
public convenience init(callback2: @escaping (
23-
_ resolve: @escaping ((()) -> Void),
24+
_ resolve: @escaping (() -> Void),
2425
_ reject: @escaping ((Error) -> Void),
2526
_ progress: @escaping ((Float) -> Void)) -> Void) {
2627
self.init()
2728
setProgressCallBack { resolve, reject, progress in
28-
callback2(resolve, reject, progress)
29+
let wrapped = { resolve(()) }
30+
callback2(wrapped, reject, progress)
2931
}
3032
}
3133
}

then.xcodeproj/project.pbxproj

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@
472472
};
473473
99B5ACA01C66831C005CDA28 = {
474474
CreatedOnToolsVersion = 7.2;
475-
LastSwiftMigration = 0900;
475+
LastSwiftMigration = 1020;
476476
};
477477
99FA7FB11D93C153002274B0 = {
478478
CreatedOnToolsVersion = 8.0;
@@ -711,7 +711,7 @@
711711
SDKROOT = appletvos;
712712
SKIP_INSTALL = YES;
713713
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
714-
SWIFT_VERSION = 4.2;
714+
SWIFT_VERSION = 5.0;
715715
TARGETED_DEVICE_FAMILY = 3;
716716
TVOS_DEPLOYMENT_TARGET = 9.0;
717717
};
@@ -736,7 +736,7 @@
736736
SDKROOT = appletvos;
737737
SKIP_INSTALL = YES;
738738
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
739-
SWIFT_VERSION = 4.2;
739+
SWIFT_VERSION = 5.0;
740740
TARGETED_DEVICE_FAMILY = 3;
741741
TVOS_DEPLOYMENT_TARGET = 9.0;
742742
};
@@ -795,7 +795,7 @@
795795
ONLY_ACTIVE_ARCH = YES;
796796
SDKROOT = iphoneos;
797797
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
798-
SWIFT_VERSION = 4.2;
798+
SWIFT_VERSION = 5.0;
799799
TARGETED_DEVICE_FAMILY = "1,2";
800800
VERSIONING_SYSTEM = "apple-generic";
801801
VERSION_INFO_PREFIX = "";
@@ -847,7 +847,7 @@
847847
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
848848
MTL_ENABLE_DEBUG_INFO = NO;
849849
SDKROOT = iphoneos;
850-
SWIFT_VERSION = 4.2;
850+
SWIFT_VERSION = 5.0;
851851
TARGETED_DEVICE_FAMILY = "1,2";
852852
VALIDATE_PRODUCT = YES;
853853
VERSIONING_SYSTEM = "apple-generic";
@@ -907,8 +907,7 @@
907907
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
908908
PRODUCT_BUNDLE_IDENTIFIER = com.s4cha.then.thenTests;
909909
PRODUCT_NAME = "$(TARGET_NAME)";
910-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
911-
SWIFT_VERSION = 4.2;
910+
SWIFT_VERSION = 5.0;
912911
};
913912
name = Debug;
914913
};
@@ -921,8 +920,7 @@
921920
PRODUCT_BUNDLE_IDENTIFIER = com.s4cha.then.thenTests;
922921
PRODUCT_NAME = "$(TARGET_NAME)";
923922
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
924-
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
925-
SWIFT_VERSION = 4.2;
923+
SWIFT_VERSION = 5.0;
926924
};
927925
name = Release;
928926
};
@@ -948,7 +946,7 @@
948946
SDKROOT = macosx;
949947
SKIP_INSTALL = YES;
950948
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
951-
SWIFT_VERSION = 4.2;
949+
SWIFT_VERSION = 5.0;
952950
};
953951
name = Debug;
954952
};
@@ -974,7 +972,7 @@
974972
SDKROOT = macosx;
975973
SKIP_INSTALL = YES;
976974
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
977-
SWIFT_VERSION = 4.2;
975+
SWIFT_VERSION = 5.0;
978976
};
979977
name = Release;
980978
};

thenTests/Helpers.swift

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,35 +115,25 @@ func waitTime(_ time: Double, callback: @escaping () -> Void) {
115115
}
116116

117117
func upload() -> Promise<Void> {
118-
119-
let callback: ((_ resolve: @escaping ((()) -> Void), _ reject: @escaping ((Error) -> Void), _ progress: @escaping ((Float) -> Void)) -> Void)
120-
= { (resolve: @escaping ((()) -> Void), _: @escaping ((Error) -> Void), progress: @escaping ((Float) -> Void)) in
118+
return Promise { (resolve: @escaping (() -> Void), _: @escaping ((Error) -> Void), progress) in
121119
waitTime {
122120
progress(0.8)
123121
waitTime {
124-
resolve(())
122+
resolve()
125123
}
126124
}
127-
128125
}
129-
130-
return Promise<Void>(callback2: callback)
131126
}
132127

133128
func failingUpload() -> Promise<Void> {
134-
135-
let callback: ((_ resolve: @escaping ((()) -> Void), _ reject: @escaping ((Error) -> Void), _ progress: @escaping ((Float) -> Void)) -> Void)
136-
= { (_: @escaping ((()) -> Void), reject: @escaping ((Error) -> Void), progress: @escaping ((Float) -> Void)) in
129+
return Promise { (_: @escaping (() -> Void), reject: @escaping ((Error) -> Void), progress) in
130+
waitTime {
131+
progress(0.8)
137132
waitTime {
138-
progress(0.8)
139-
waitTime {
140-
reject(NSError(domain: "", code: 1223, userInfo: nil))
141-
}
133+
reject(NSError(domain: "", code: 1223, userInfo: nil))
142134
}
135+
}
143136
}
144-
145-
146-
return Promise<Void>(callback2: callback)
147137
}
148138

149139
enum MyError: Error {

0 commit comments

Comments
 (0)