From 456a2d7f95fddf8dd373e913f4de4f9c158725a8 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Tue, 22 Mar 2016 08:50:43 +0900 Subject: [PATCH 01/24] Update for Swift 2.2 (Xcode 7.3) --- SwiftTask.xcodeproj/project.pbxproj | 4 +- .../xcshareddata/xcschemes/SwiftTask.xcscheme | 2 +- SwiftTask/Cancellable.swift | 2 +- SwiftTask/SwiftTask.swift | 8 +- SwiftTask/_StateMachine.swift | 4 +- SwiftTaskTests/AlamofireTests.swift | 10 +- SwiftTaskTests/BasicTests.swift | 2 +- SwiftTaskTests/MultipleErrorTypesTests.swift | 10 +- SwiftTaskTests/RemoveHandlerTests.swift | 4 +- SwiftTaskTests/RetainCycleTests.swift | 8 +- SwiftTaskTests/SwiftTaskTests.swift | 96 +++++++++---------- 11 files changed, 76 insertions(+), 74 deletions(-) diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index c33b532..df1c856 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -297,7 +297,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0700; + LastUpgradeCheck = 0730; ORGANIZATIONNAME = "Yasuhiro Inami"; TargetAttributes = { 1F46DED3199EDF1000F97868 = { @@ -502,6 +502,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -520,6 +521,7 @@ buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; CLANG_ENABLE_MODULES = YES; + COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme index b29280b..b13a783 100644 --- a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme +++ b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme @@ -1,6 +1,6 @@ Void in lock.lock() - completedCount++ + completedCount += 1 let progressTuple = BulkProgress(completedCount: completedCount, totalCount: totalCount) progress(progressTuple) @@ -754,7 +754,7 @@ extension Task task.success { (value: Value) -> Void in lock.lock() - completedCount++ + completedCount += 1 if completedCount == 1 { fulfill(value) @@ -766,7 +766,7 @@ extension Task }.failure { (errorInfo: ErrorInfo) -> Void in lock.lock() - rejectedCount++ + rejectedCount += 1 if rejectedCount == totalCount { let isAnyCancelled = (tasks.filter { task in task.state == .Cancelled }.count > 0) @@ -803,7 +803,7 @@ extension Task task.then { (value: Value?, errorInfo: ErrorInfo?) -> Void in lock.lock() - completedCount++ + completedCount += 1 let progressTuple = BulkProgress(completedCount: completedCount, totalCount: totalCount) progress(progressTuple) diff --git a/SwiftTask/_StateMachine.swift b/SwiftTask/_StateMachine.swift index 82a7e17..50f0fa9 100644 --- a/SwiftTask/_StateMachine.swift +++ b/SwiftTask/_StateMachine.swift @@ -262,7 +262,7 @@ internal struct _Handlers: SequenceType internal mutating func remove(token: _HandlerToken) -> T? { - for var i = 0; i < self.elements.count; i++ { + for i in 0..: SequenceType internal func generate() -> AnyGenerator { - return anyGenerator(self.elements.map { $0.value }.generate()) + return AnyGenerator(self.elements.map { $0.value }.generate()) } } \ No newline at end of file diff --git a/SwiftTaskTests/AlamofireTests.swift b/SwiftTaskTests/AlamofireTests.swift index 1bc690c..543442c 100644 --- a/SwiftTaskTests/AlamofireTests.swift +++ b/SwiftTaskTests/AlamofireTests.swift @@ -16,7 +16,7 @@ class AlamofireTests: _TestCase func testFulfill() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let task = Task { progress, fulfill, reject, configure in @@ -46,7 +46,7 @@ class AlamofireTests: _TestCase func testReject() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let task = Task { progress, fulfill, reject, configure in @@ -86,7 +86,7 @@ class AlamofireTests: _TestCase func testProgress() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // define task let task = Task { progress, fulfill, reject, configure in @@ -129,7 +129,7 @@ class AlamofireTests: _TestCase func testNSProgress() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let nsProgress = NSProgress(totalUnitCount: 100) // define task @@ -176,7 +176,7 @@ class AlamofireTests: _TestCase // func testCancel() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let task = Task { progress, fulfill, reject, configure in diff --git a/SwiftTaskTests/BasicTests.swift b/SwiftTaskTests/BasicTests.swift index 1a538f6..8e541b5 100644 --- a/SwiftTaskTests/BasicTests.swift +++ b/SwiftTaskTests/BasicTests.swift @@ -16,7 +16,7 @@ class BasicTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // define task let task = Task { progress, fulfill, reject, configure in diff --git a/SwiftTaskTests/MultipleErrorTypesTests.swift b/SwiftTaskTests/MultipleErrorTypesTests.swift index 414dc83..2574855 100644 --- a/SwiftTaskTests/MultipleErrorTypesTests.swift +++ b/SwiftTaskTests/MultipleErrorTypesTests.swift @@ -61,7 +61,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_then() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) self._task1(ok: true) .then { value, errorInfo -> Task2 in @@ -87,7 +87,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) self._task1(ok: true) .success { value -> Task2 in @@ -113,7 +113,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) self._task1(ok: true) .success { value -> Task2 in @@ -151,7 +151,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType_conversion() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) self._task1(ok: true) .success { value -> Task in @@ -191,7 +191,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_failure() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) self._task1(ok: false) .failure { errorInfo -> Task in diff --git a/SwiftTaskTests/RemoveHandlerTests.swift b/SwiftTaskTests/RemoveHandlerTests.swift index 0c2f100..47fe13a 100644 --- a/SwiftTaskTests/RemoveHandlerTests.swift +++ b/SwiftTaskTests/RemoveHandlerTests.swift @@ -16,7 +16,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var latestProgressValue: Float? var canceller: AutoCanceller? = nil @@ -60,7 +60,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var canceller: AutoCanceller? = nil // define task diff --git a/SwiftTaskTests/RetainCycleTests.swift b/SwiftTaskTests/RetainCycleTests.swift index 134e134..a075a09 100644 --- a/SwiftTaskTests/RetainCycleTests.swift +++ b/SwiftTaskTests/RetainCycleTests.swift @@ -54,7 +54,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_notConfigured() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // // retain cycle: @@ -98,7 +98,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_configured() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // // retain cycle: @@ -144,7 +144,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_notConfigured() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // // retain cycle: @@ -186,7 +186,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_configured() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) // // retain cycle: diff --git a/SwiftTaskTests/SwiftTaskTests.swift b/SwiftTaskTests/SwiftTaskTests.swift index f9be681..b7fedd6 100644 --- a/SwiftTaskTests/SwiftTaskTests.swift +++ b/SwiftTaskTests/SwiftTaskTests.swift @@ -70,7 +70,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -90,7 +90,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_failure() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -114,7 +114,7 @@ class SwiftTaskTests: _TestCase func testFulfill_failure_success() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -140,7 +140,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_fulfill() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -172,7 +172,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_reject() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -212,7 +212,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -244,7 +244,7 @@ class SwiftTaskTests: _TestCase func testReject_failure() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -266,7 +266,7 @@ class SwiftTaskTests: _TestCase func testReject_success_failure() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -292,7 +292,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_success() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -320,7 +320,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_fulfill() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -353,7 +353,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_reject() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -394,7 +394,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task { progress, fulfill, reject, configure in @@ -428,7 +428,7 @@ class SwiftTaskTests: _TestCase func testOn_success() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -450,7 +450,7 @@ class SwiftTaskTests: _TestCase func testOn_failure() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -479,7 +479,7 @@ class SwiftTaskTests: _TestCase func testProgress() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 Task { progress, fulfill, reject, configure in @@ -492,7 +492,7 @@ class SwiftTaskTests: _TestCase }.progress { oldProgress, newProgress in - progressCount++ + progressCount += 1 if self.isAsync { // 0.0 <= progress <= 1.0 @@ -530,7 +530,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -542,7 +542,7 @@ class SwiftTaskTests: _TestCase } task3.progress { progressValues in - progressCount++ + progressCount += 1 print(progressValues) return }.success { value -> Void in @@ -559,7 +559,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -571,7 +571,7 @@ class SwiftTaskTests: _TestCase } task3.progress { progressValues in - progressCount++ + progressCount += 1 print(progressValues) return }.success { value -> Void in @@ -588,7 +588,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 let task = _interruptableTask(progressCount: 5, finalState: .Rejected) // 1st async task (5 progresses -> rejected) @@ -600,7 +600,7 @@ class SwiftTaskTests: _TestCase } task3.progress { progressValues in - progressCount++ + progressCount += 1 print(progressValues) return }.success { value -> Void in @@ -618,14 +618,14 @@ class SwiftTaskTests: _TestCase func testCancel() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) task.progress { oldProgress, newProgress in - progressCount++ + progressCount += 1 // 1 <= progressCount <= 3 (not 5) XCTAssertGreaterThanOrEqual(progressCount, 1) @@ -660,7 +660,7 @@ class SwiftTaskTests: _TestCase func testCancel_then_innerTask() { - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let task1 = _interruptableTask(progressCount: 5) @@ -707,14 +707,14 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) task.progress { _ in - progressCount++ + progressCount += 1 return }.success { value -> Void in @@ -754,7 +754,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let task = _interruptableTask(progressCount: 5) weak var innerTask: _InterruptableTask? @@ -823,7 +823,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let maxTryCount = 3 let fulfilledTryCount = 2 var actualTryCount = 0 @@ -832,7 +832,7 @@ class SwiftTaskTests: _TestCase self.perform { - actualTryCount++ + actualTryCount += 1 if actualTryCount != fulfilledTryCount { reject("ERROR \(actualTryCount)") @@ -865,14 +865,14 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let maxTryCount = 3 var actualTryCount = 0 Task { progress, fulfill, reject, configure in self.perform { - actualTryCount++ + actualTryCount += 1 reject("ERROR \(actualTryCount)") } @@ -897,7 +897,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let maxTryCount = 3 var actualTryCount = 0 var progressCount = 0 @@ -908,7 +908,7 @@ class SwiftTaskTests: _TestCase progress(1.0) - actualTryCount++ + actualTryCount += 1 if actualTryCount < maxTryCount { reject("ERROR \(actualTryCount)") @@ -920,7 +920,7 @@ class SwiftTaskTests: _TestCase }.retry(maxTryCount-1).progress { _ in - progressCount++ + progressCount += 1 // 1 <= progressCount <= maxTryCount XCTAssertGreaterThanOrEqual(progressCount, 1) @@ -943,13 +943,13 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let maxTryCount = 5 var actualTryCount = 0 let retryableTask = Task { progress, fulfill, reject, configure in - actualTryCount++ + actualTryCount += 1 print("trying \(actualTryCount)") var isPaused = false @@ -1008,7 +1008,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) let maxTryCount = 3 var actualTryCount = 0 @@ -1016,7 +1016,7 @@ class SwiftTaskTests: _TestCase Async.main(after: 0.3) { - actualTryCount++ + actualTryCount += 1 if actualTryCount < maxTryCount { reject("ERROR \(actualTryCount)") @@ -1077,7 +1077,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1135,7 +1135,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<5 { @@ -1183,7 +1183,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1240,7 +1240,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1312,7 +1312,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1357,7 +1357,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1398,7 +1398,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1455,7 +1455,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1525,7 +1525,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(__FUNCTION__) + let expect = self.expectationWithDescription(#function) var tasks: [Task] = Array() for i in 0..<10 { From 8825287c7aede204a69cf2eafe0d01d7beb83e14 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Tue, 22 Mar 2016 08:58:58 +0900 Subject: [PATCH 02/24] Update circle.yml --- circle.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/circle.yml b/circle.yml index 88c6b8c..f2f65a3 100644 --- a/circle.yml +++ b/circle.yml @@ -1,6 +1,6 @@ machine: xcode: - version: "7.2" + version: "7.3" checkout: post: From ead845a2b86e5b46e1c6f392792fd3a74257c0aa Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Sat, 7 May 2016 12:59:13 +0900 Subject: [PATCH 03/24] [Test] Add MultipleTasksTests --- SwiftTask.xcodeproj/project.pbxproj | 6 ++ SwiftTaskTests/MultipleTasksTests.swift | 136 ++++++++++++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 SwiftTaskTests/MultipleTasksTests.swift diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index df1c856..7afd54e 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -27,6 +27,8 @@ 1FD7197B1AFE387C00BC38C4 /* Cancellable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FD7197A1AFE387C00BC38C4 /* Cancellable.swift */; }; 1FF52EB41A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF52EB31A4C395A00B4BA28 /* _InterruptableTask.swift */; }; 1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF52EB31A4C395A00B4BA28 /* _InterruptableTask.swift */; }; + 1FF95CB01CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */; }; + 1FF95CB11CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */; }; 4822F0DC19D00B2300F5F572 /* _TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFC199EE2C200F97868 /* _TestCase.swift */; }; 4822F0DD19D00B2300F5F572 /* BasicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F20250119ADA8FD00DE0495 /* BasicTests.swift */; }; 4822F0DE19D00B2300F5F572 /* SwiftTaskTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEE3199EDF1000F97868 /* SwiftTaskTests.swift */; }; @@ -76,6 +78,7 @@ 1FCF71151AD8CD38007079C2 /* Alamofire.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Alamofire.framework; path = ../Carthage/Checkouts/Alamofire/build/Debug/Alamofire.framework; sourceTree = ""; }; 1FD7197A1AFE387C00BC38C4 /* Cancellable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cancellable.swift; sourceTree = ""; }; 1FF52EB31A4C395A00B4BA28 /* _InterruptableTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = _InterruptableTask.swift; sourceTree = ""; }; + 1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultipleTasksTests.swift; sourceTree = ""; }; 1FFADCCF1C5CE950000B66BE /* Base.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = ""; }; 1FFADCD01C5CE950000B66BE /* Debug.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = ""; }; 1FFADCD11C5CE950000B66BE /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = ""; }; @@ -174,6 +177,7 @@ 1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */, 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */, 1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */, + 1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */, 1F46DEE1199EDF1000F97868 /* Supporting Files */, ); path = SwiftTaskTests; @@ -375,6 +379,7 @@ 1F20250219ADA8FD00DE0495 /* BasicTests.swift in Sources */, 1FF52EB41A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */, 1F218D5B1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */, + 1FF95CB01CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */, 1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */, 1F29F6421B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */, 1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */, @@ -391,6 +396,7 @@ 4822F0DE19D00B2300F5F572 /* SwiftTaskTests.swift in Sources */, 4822F0DD19D00B2300F5F572 /* BasicTests.swift in Sources */, 1F218D5C1AFC3FFD00C849FF /* RemoveHandlerTests.swift in Sources */, + 1FF95CB11CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */, 1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */, 1F29F6431B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */, 1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */, diff --git a/SwiftTaskTests/MultipleTasksTests.swift b/SwiftTaskTests/MultipleTasksTests.swift new file mode 100644 index 0000000..5ac3e77 --- /dev/null +++ b/SwiftTaskTests/MultipleTasksTests.swift @@ -0,0 +1,136 @@ +// +// MultipleTasksTests.swift +// SwiftTask +// +// Created by Yasuhiro Inami on 2016-05-07. +// Copyright © 2016 Yasuhiro Inami. All rights reserved. +// + +import SwiftTask +import XCTest + +/// Generic type for value/error to demonstrate multiple tasks working on different types. +private enum MyEnum { case Default } + +private typealias Value1 = MyEnum<()> +private typealias Error1 = MyEnum +private typealias Value2 = MyEnum +private typealias Error2 = MyEnum +private typealias Value3 = MyEnum +private typealias Error3 = MyEnum + +/// Wrapped error type to unify `Error1`/`Error2`/`Error3`. +private enum WrappedError +{ + case ByTask1(Error1) + case ByTask2(Error2) + case ByTask3(Error3) + + /// For external cancellation -> internal rejection conversion. + case Cancelled +} + +class MultipleTasksTests: _TestCase +{ + func testMultipleTasksTests_success1_success2_success3() + { + let expect = self.expectationWithDescription(#function) + + var flow = [Int]() + + let task1 = { Task<(), Value1, Error1>(value: .Default).on(success: { _ in flow.append(1) }) } + let task2 = { Task<(), Value2, Error2>(value: .Default).on(success: { _ in flow.append(2) }) } + let task3 = { Task<(), Value3, Error3>(value: .Default).on(success: { _ in flow.append(3) }) } + + task1()._mapError(WrappedError.ByTask1) + .success { _ in + task2()._mapError(WrappedError.ByTask2) + } + .success { _ in + task3()._mapError(WrappedError.ByTask3) + } + .on(success: { _ in + XCTAssertEqual(flow, [1, 2, 3]) + expect.fulfill() + }) + + self.wait() + } + + func testMultipleTasksTests_success1_success2_failure3() + { + let expect = self.expectationWithDescription(#function) + + var flow = [Int]() + + let task1 = { Task<(), Value1, Error1>(value: .Default).on(success: { _ in flow.append(1) }) } + let task2 = { Task<(), Value2, Error2>(value: .Default).on(success: { _ in flow.append(2) }) } + let task3 = { Task<(), Value3, Error3>(error: .Default).on(success: { _ in flow.append(3) }) } + + task1()._mapError(WrappedError.ByTask1) + .success { _ in + task2()._mapError(WrappedError.ByTask2) + } + .success { _ in + task3()._mapError(WrappedError.ByTask3) + } + .on(failure: { error, isCancelled in + guard case let .Some(.ByTask3(error3)) = error else { + XCTFail("Wrong WrappedError.") + return + } + XCTAssertEqual(error3, Error3.Default) + XCTAssertEqual(flow, [1, 2]) + expect.fulfill() + }) + + self.wait() + } + + func testMultipleTasksTests_success1_failure2_success3() + { + let expect = self.expectationWithDescription(#function) + + var flow = [Int]() + + let task1 = { Task<(), Value1, Error1>(value: .Default).on(success: { _ in flow.append(1) }) } + let task2 = { Task<(), Value2, Error2>(error: .Default).on(success: { _ in flow.append(2) }) } + let task3 = { Task<(), Value3, Error3>(value: .Default).on(success: { _ in flow.append(3) }) } + + task1()._mapError(WrappedError.ByTask1) + .success { _ in + task2()._mapError(WrappedError.ByTask2) + } + .success { _ in + task3()._mapError(WrappedError.ByTask3) + } + .on(failure: { error, isCancelled in + guard case let .Some(.ByTask2(error2)) = error else { + XCTFail("Wrong WrappedError.") + return + } + XCTAssertEqual(error2, Error2.Default) + XCTAssertEqual(flow, [1]) + expect.fulfill() + }) + + self.wait() + } +} + +extension Task +{ + /// Converts `Task<..., Error>` to `Task<..., WrappedError>`. + private func _mapError(f: Error -> WrappedError) -> Task + { + return self.failure { error, isCancelled -> Task in + if let error = error { + return Task(error: f(error)) + } + else { + // converts external cancellation -> internal rejection + return Task(error: .Cancelled) + } + } + } +} From 902335dbbaac1102600ce9d6505196e7560109f1 Mon Sep 17 00:00:00 2001 From: akio0911 Date: Sun, 8 May 2016 11:57:55 +0900 Subject: [PATCH 04/24] [Test] Add wrappedErrorTask --- SwiftTaskTests/MultipleTasksTests.swift | 43 +++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/SwiftTaskTests/MultipleTasksTests.swift b/SwiftTaskTests/MultipleTasksTests.swift index 5ac3e77..d9a237f 100644 --- a/SwiftTaskTests/MultipleTasksTests.swift +++ b/SwiftTaskTests/MultipleTasksTests.swift @@ -116,6 +116,43 @@ class MultipleTasksTests: _TestCase self.wait() } + + func testMultipleTasksTests_success1_failure2_success3_wrapped() + { + let expect = self.expectationWithDescription(#function) + + var flow = [Int]() + + let task1 = { Task<(), Value1, Error1>(value: .Default).on(success: { _ in flow.append(1) }) } + let wrapped1 = wrappedErrorTask(task1, f: WrappedError.ByTask1) + + let task2 = { Task<(), Value2, Error2>(error: .Default).on(success: { _ in flow.append(2) }) } + let wrapped2 = wrappedErrorTask(task2, f: WrappedError.ByTask2) + + let task3 = { Task<(), Value3, Error3>(value: .Default).on(success: { _ in flow.append(3) }) } + let wrapped3 = wrappedErrorTask(task3, f: WrappedError.ByTask3) + + XCTAssertEqual(flow, []) + + wrapped1() + .success { _ in + wrapped2() + } + .success { _ in + wrapped3() + } + .on(failure: { error, isCancelled in + guard case let .Some(.ByTask2(error2)) = error else { + XCTFail("Wrong WrappedError.") + return + } + XCTAssertEqual(error2, Error2.Default) + XCTAssertEqual(flow, [1]) + expect.fulfill() + }) + + self.wait() + } } extension Task @@ -134,3 +171,9 @@ extension Task } } } + +private func wrappedErrorTask(task: () -> Task, f: E -> WrappedError) -> () -> Task { + return { + task()._mapError(f) + } +} From 443fc9b88e4d4f7528c686f3a706a86ed9ed5103 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Thu, 2 Jun 2016 10:31:41 +0900 Subject: [PATCH 05/24] Update podspec --- SwiftTask.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftTask.podspec b/SwiftTask.podspec index fb46c3b..33bcce6 100644 --- a/SwiftTask.podspec +++ b/SwiftTask.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'SwiftTask' - s.version = '4.2.1' + s.version = '5.0.0' s.license = { :type => 'MIT' } s.homepage = 'https://github.com/ReactKit/SwiftTask' s.authors = { 'Yasuhiro Inami' => 'inamiy@gmail.com' } From a38661a02501b27eca6f0835f7dd50979324f8a7 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Sun, 5 Jun 2016 19:08:10 +0900 Subject: [PATCH 06/24] Fix redundant recursive calls in `Task.all` --- SwiftTask/SwiftTask.swift | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index e69c25e..7fec21b 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -699,6 +699,7 @@ extension Task var completedCount = 0 let totalCount = tasks.count let lock = _RecursiveLock() + let cancelled = _Atomic(false) for task in tasks { task.success { (value: Value) -> Void in @@ -721,20 +722,27 @@ extension Task lock.unlock() }.failure { (errorInfo: ErrorInfo) -> Void in - - lock.lock() - _reject(errorInfo) - - for task in tasks { - task.cancel() + + let changed = cancelled.updateIf { $0 == false ? true : nil } + if changed != nil { + lock.lock() + _reject(errorInfo) + + for task in tasks { + task.cancel() + } + lock.unlock() } - lock.unlock() } } configure.pause = { self.pauseAll(tasks); return } configure.resume = { self.resumeAll(tasks); return } - configure.cancel = { self.cancelAll(tasks); return } + configure.cancel = { + if !cancelled.rawValue { + self.cancelAll(tasks); + } + } }.name("Task.all") } From 655b494b73d3c9231d8e6c41fc84ad284c3bcd1b Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Sun, 19 Jun 2016 16:22:16 -0700 Subject: [PATCH 07/24] Update dependencies --- Cartfile.private | 4 ++-- Cartfile.resolved | 4 ++-- Carthage/Checkouts/Async | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Cartfile.private b/Cartfile.private index d9d7524..4238969 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ -github "Alamofire/Alamofire" ~> 3.1.3 -github "duemunk/Async" ~> 1.6.4 +github "Alamofire/Alamofire" "swift3" +github "duemunk/Async" "feature/Swift_3.0" github "mrackwitz/xcconfigs" \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index eb9efec..88415de 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,3 @@ -github "Alamofire/Alamofire" "3.1.5" -github "duemunk/Async" "1.6.4" +github "Alamofire/Alamofire" "e891699312a5215ad0da9f8322c5da949f90db35" +github "duemunk/Async" "23d32df500f7ace6ea1526e7433a0fa7004c8d7d" github "mrackwitz/xcconfigs" "3.0" diff --git a/Carthage/Checkouts/Async b/Carthage/Checkouts/Async index 3c32436..23d32df 160000 --- a/Carthage/Checkouts/Async +++ b/Carthage/Checkouts/Async @@ -1 +1 @@ -Subproject commit 3c324366ceb02e69d3ff66401ea6fb6e665ec663 +Subproject commit 23d32df500f7ace6ea1526e7433a0fa7004c8d7d From 1492825ad9df429a747361ba4a79e404244be5da Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Sun, 19 Jun 2016 16:22:56 -0700 Subject: [PATCH 08/24] Update project settings --- SwiftTask.xcodeproj/project.pbxproj | 10 +++++++++- .../xcshareddata/xcschemes/SwiftTask.xcscheme | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index 7afd54e..8d867ab 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -301,14 +301,16 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = "Yasuhiro Inami"; TargetAttributes = { 1F46DED3199EDF1000F97868 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; 1F46DEDE199EDF1000F97868 = { CreatedOnToolsVersion = 6.0; + LastSwiftMigration = 0800; }; 4822F0CF19D00ABF00F5F572 = { CreatedOnToolsVersion = 6.0.1; @@ -446,6 +448,7 @@ ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -490,6 +493,7 @@ ENABLE_NS_ASSERTIONS = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; GCC_WARN_UNDECLARED_SELECTOR = YES; @@ -518,6 +522,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -537,6 +542,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -554,6 +560,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -567,6 +574,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme index b13a783..09eb84c 100644 --- a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme +++ b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme @@ -1,6 +1,6 @@ Date: Sun, 19 Jun 2016 17:04:14 -0700 Subject: [PATCH 09/24] Migrate SwiftTask to Swift 3.0 --- Carthage/Checkouts/Alamofire | 2 +- SwiftTask/Cancellable.swift | 21 ++---- SwiftTask/SwiftTask.swift | 97 +++++++++++---------------- SwiftTask/_Atomic.swift | 10 +-- SwiftTask/_RecursiveLock.swift | 8 +-- SwiftTask/_StateMachine.swift | 36 +++++----- SwiftTaskTests/RetainCycleTests.swift | 6 +- SwiftTaskTests/_TestCase.swift | 4 +- 8 files changed, 78 insertions(+), 106 deletions(-) diff --git a/Carthage/Checkouts/Alamofire b/Carthage/Checkouts/Alamofire index fe3a299..e891699 160000 --- a/Carthage/Checkouts/Alamofire +++ b/Carthage/Checkouts/Alamofire @@ -1 +1 @@ -Subproject commit fe3a29941cd1f8d17a81a0843387743238d24d8f +Subproject commit e891699312a5215ad0da9f8322c5da949f90db35 diff --git a/SwiftTask/Cancellable.swift b/SwiftTask/Cancellable.swift index 51c6ea2..6bfcd5b 100644 --- a/SwiftTask/Cancellable.swift +++ b/SwiftTask/Cancellable.swift @@ -12,30 +12,19 @@ public protocol Cancellable { associatedtype _Error - // - // NOTE: - // Single `func cancel(error: Error) -> Bool` is preferred (as first implemented in 8a22ed5), - // but two overloaded methods are required for SwiftTask ver 3.x API compatibility. - // - func cancel() -> Bool - func cancel(error error: _Error) -> Bool + func cancel(error: _Error) -> Bool } public class Canceller: Cancellable { - private var cancelHandler: (Void -> Void)? + private var cancelHandler: (() -> Void)? - public required init(cancelHandler: Void -> Void) + public required init(cancelHandler: () -> Void) { self.cancelHandler = cancelHandler } - public func cancel() -> Bool - { - return self.cancel(error: ()) - } - - public func cancel(error error: Void) -> Bool + @discardableResult public func cancel(error: Void = ()) -> Bool { if let cancelHandler = self.cancelHandler { self.cancelHandler = nil @@ -53,4 +42,4 @@ public class AutoCanceller: Canceller { self.cancel() } -} \ No newline at end of file +} diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index 7fec21b..0afc6f2 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -27,9 +27,9 @@ public enum TaskState: String, CustomStringConvertible // NOTE: use class instead of struct to pass reference to `_initClosure` to set `pause`/`resume`/`cancel` closures public class TaskConfiguration { - public var pause: (Void -> Void)? - public var resume: (Void -> Void)? - public var cancel: (Void -> Void)? + public var pause: (() -> Void)? + public var resume: (() -> Void)? + public var cancel: (() -> Void)? /// useful to terminate immediate-infinite-sequence while performing `initClosure` public var isFinished : Bool @@ -62,9 +62,9 @@ public class Task: Cancellable, CustomStringConvertible public typealias ProgressTuple = (oldProgress: Progress?, newProgress: Progress) public typealias ErrorInfo = (error: Error?, isCancelled: Bool) - public typealias ProgressHandler = (Progress -> Void) - public typealias FulfillHandler = (Value -> Void) - public typealias RejectHandler = (Error -> Void) + public typealias ProgressHandler = (Progress) -> Void + public typealias FulfillHandler = (Value) -> Void + public typealias RejectHandler = (Error) -> Void public typealias Configuration = TaskConfiguration public typealias PromiseInitClosure = (fulfill: FulfillHandler, reject: RejectHandler) -> Void @@ -74,8 +74,8 @@ public class Task: Cancellable, CustomStringConvertible internal typealias _InitClosure = (machine: _Machine, progress: ProgressHandler, fulfill: FulfillHandler, _reject: _RejectInfoHandler, configure: TaskConfiguration) -> Void - internal typealias _ProgressTupleHandler = (ProgressTuple -> Void) - internal typealias _RejectInfoHandler = (ErrorInfo -> Void) + internal typealias _ProgressTupleHandler = (ProgressTuple) -> Void + internal typealias _RejectInfoHandler = (ErrorInfo) -> Void internal let _machine: _Machine @@ -210,7 +210,7 @@ public class Task: Cancellable, CustomStringConvertible } // NOTE: don't use `internal init` for this setup method, or this will be a designated initializer - internal func setup(weakified weakified: Bool, paused: Bool, _initClosure: _InitClosure) + internal func setup(weakified: Bool, paused: Bool, _initClosure: _InitClosure) { // #if DEBUG // let addr = String(format: "%p", unsafeAddressOf(self)) @@ -293,11 +293,11 @@ public class Task: Cancellable, CustomStringConvertible // #endif // cancel in case machine is still running - self._cancel(nil) + self.cancel(error: nil) } /// Sets task name (method chainable) - public func name(name: String) -> Self + public func name(_ name: String) -> Self { self.name = name return self @@ -312,7 +312,7 @@ public class Task: Cancellable, CustomStringConvertible } /// Returns new task that is retryable for `maxRetryCount (= maxTryCount-1)` times. - public func retry(maxRetryCount: Int) -> Task + public func retry(_ maxRetryCount: Int) -> Task { if maxRetryCount < 1 { return self } @@ -356,13 +356,13 @@ public class Task: Cancellable, CustomStringConvertible /// - Note: `oldProgress` is always nil when `weakified = true` /// - Returns: Self (same `Task`) /// - public func progress(progressClosure: ProgressTuple -> Void) -> Self + @discardableResult public func progress(progressClosure: (ProgressTuple) -> Void) -> Self { var dummyCanceller: Canceller? = nil return self.progress(&dummyCanceller, progressClosure) } - public func progress(inout canceller: C?, _ progressClosure: ProgressTuple -> Void) -> Self + public func progress(_ canceller: inout C?, _ progressClosure: (ProgressTuple) -> Void) -> Self { var token: _HandlerToken? = nil self._machine.addProgressTupleHandler(&token, progressClosure) @@ -382,13 +382,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func then(thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task + @discardableResult public func then(thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) } - public func then(inout canceller: C?, _ thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task + public func then(_ canceller: inout C?, _ thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task { return self.then(&canceller) { (value, errorInfo) -> Task in return Task(value: thenClosure(value, errorInfo)) @@ -417,7 +417,7 @@ public class Task: Cancellable, CustomStringConvertible // /// - Returns: New `Task` /// - public func then(inout canceller: C?, _ thenClosure: (Value?, ErrorInfo?) -> Task) -> Task + public func then(_ canceller: inout C?, _ thenClosure: (Value?, ErrorInfo?) -> Task) -> Task { return Task { [unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in @@ -439,7 +439,7 @@ public class Task: Cancellable, CustomStringConvertible } /// invokes `completionHandler` "now" or "in the future" - private func _then(inout canceller: C?, _ completionHandler: Void -> Void) + private func _then(_ canceller: inout C?, _ completionHandler: () -> Void) { switch self.state { case .Fulfilled, .Rejected, .Cancelled: @@ -462,13 +462,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func success(successClosure: Value -> Value2) -> Task + @discardableResult public func success(successClosure: (Value) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) } - public func success(inout canceller: C?, _ successClosure: Value -> Value2) -> Task + public func success(_ canceller: inout C?, _ successClosure: (Value) -> Value2) -> Task { return self.success(&canceller) { (value: Value) -> Task in return Task(value: successClosure(value)) @@ -483,13 +483,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func success(successClosure: Value -> Task) -> Task + public func success(successClosure: (Value) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) } - public func success(inout canceller: C?, _ successClosure: Value -> Task) -> Task + public func success(_ canceller: inout C?, _ successClosure: (Value) -> Task) -> Task { return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in @@ -518,13 +518,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func failure(failureClosure: ErrorInfo -> Value) -> Task + @discardableResult public func failure(failureClosure: (ErrorInfo) -> Value) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) } - public func failure(inout canceller: C?, _ failureClosure: ErrorInfo -> Value) -> Task + public func failure(_ canceller: inout C?, _ failureClosure: (ErrorInfo) -> Value) -> Task { return self.failure(&canceller) { (errorInfo: ErrorInfo) -> Task in return Task(value: failureClosure(errorInfo)) @@ -540,13 +540,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func failure(failureClosure: ErrorInfo -> Task) -> Task + public func failure(failureClosure: (ErrorInfo) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) } - public func failure(inout canceller: C?, _ failureClosure: ErrorInfo -> Task) -> Task + public func failure(_ canceller: inout C?, _ failureClosure: (ErrorInfo) -> Task) -> Task { return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in @@ -571,13 +571,13 @@ public class Task: Cancellable, CustomStringConvertible /// - Note: This method doesn't create new task, so it has better performance over `then()`/`success()`/`failure()`. /// - Returns: Self (same `Task`) /// - public func on(success success: (Value -> Void)? = nil, failure: (ErrorInfo -> Void)? = nil) -> Self + @discardableResult public func on(success: ((Value) -> Void)? = nil, failure: ((ErrorInfo) -> Void)? = nil) -> Self { var dummyCanceller: Canceller? = nil return self.on(&dummyCanceller, success: success, failure: failure) } - public func on(inout canceller: C?, success: (Value -> Void)? = nil, failure: (ErrorInfo -> Void)? = nil) -> Self + public func on(_ canceller: inout C?, success: ((Value) -> Void)? = nil, failure: ((ErrorInfo) -> Void)? = nil) -> Self { let selfMachine = self._machine @@ -594,36 +594,19 @@ public class Task: Cancellable, CustomStringConvertible } /// Pause task. - public func pause() -> Bool + @discardableResult public func pause() -> Bool { return self._machine.handlePause() } /// Resume task. - public func resume() -> Bool + @discardableResult public func resume() -> Bool { return self._machine.handleResume() } - // - // NOTE: - // To conform to `Cancellable`, this method is needed in replace of: - // - `public func cancel(error: Error? = nil) -> Bool` - // - `public func cancel(_ error: Error? = nil) -> Bool` (segfault in Swift 1.2) - // - /// Cancel task. - public func cancel() -> Bool - { - return self.cancel(error: nil) - } - /// Cancel task. - public func cancel(error error: Error?) -> Bool - { - return self._cancel(error) - } - - internal func _cancel(error: Error? = nil) -> Bool + @discardableResult public func cancel(error: Error? = nil) -> Bool { return self._machine.handleCancel(error) } @@ -633,7 +616,7 @@ public class Task: Cancellable, CustomStringConvertible // MARK: - Helper internal func _bindInnerTask( - innerTask: Task, + _ innerTask: Task, _ newMachine: _StateMachine, _ progress: Task.ProgressHandler, _ fulfill: Task.FulfillHandler, @@ -688,7 +671,7 @@ extension Task { public typealias BulkProgress = (completedCount: Int, totalCount: Int) - public class func all(tasks: [Task]) -> Task + public class func all(_ tasks: [Task]) -> Task { guard !tasks.isEmpty else { return Task(value: []) @@ -747,7 +730,7 @@ extension Task }.name("Task.all") } - public class func any(tasks: [Task]) -> Task + public class func any(_ tasks: [Task]) -> Task { precondition(!tasks.isEmpty, "`Task.any(tasks)` with empty `tasks` should not be called. It will never be fulfilled or rejected.") @@ -795,7 +778,7 @@ extension Task /// Returns new task which performs all given tasks and stores only fulfilled values. /// This new task will NEVER be internally rejected. - public class func some(tasks: [Task]) -> Task + public class func some(_ tasks: [Task]) -> Task { guard !tasks.isEmpty else { return Task(value: []) @@ -839,24 +822,24 @@ extension Task }.name("Task.some") } - public class func cancelAll(tasks: [Task]) + public class func cancelAll(_ tasks: [Task]) { for task in tasks { - task._cancel() + task.cancel() } } - public class func pauseAll(tasks: [Task]) + public class func pauseAll(_ tasks: [Task]) { for task in tasks { task.pause() } } - public class func resumeAll(tasks: [Task]) + public class func resumeAll(_ tasks: [Task]) { for task in tasks { task.resume() } } -} \ No newline at end of file +} diff --git a/SwiftTask/_Atomic.swift b/SwiftTask/_Atomic.swift index 0f14c1a..6001143 100644 --- a/SwiftTask/_Atomic.swift +++ b/SwiftTask/_Atomic.swift @@ -18,7 +18,7 @@ internal final class _Atomic self._rawValue = rawValue } - internal func withRawValue(@noescape f: T -> U) -> U + internal func withRawValue(_ f: @noescape (T) -> U) -> U { self._lock() defer { self._unlock() } @@ -26,17 +26,17 @@ internal final class _Atomic return f(self._rawValue) } - internal func update(@noescape f: T -> T) -> T + internal func update(_ f: @noescape (T) -> T) -> T { return self.updateIf { f($0) }! } - internal func updateIf(@noescape f: T -> T?) -> T? + internal func updateIf(_ f: @noescape (T) -> T?) -> T? { return self.modify { value in f(value).map { ($0, value) } } } - internal func modify(@noescape f: T -> (T, U)?) -> U? + internal func modify(_ f: @noescape (T) -> (T, U)?) -> U? { self._lock() defer { self._unlock() } @@ -93,4 +93,4 @@ extension _Atomic: CustomStringConvertible { return String(self.rawValue) } -} \ No newline at end of file +} diff --git a/SwiftTask/_RecursiveLock.swift b/SwiftTask/_RecursiveLock.swift index fb0a279..16bfc8d 100644 --- a/SwiftTask/_RecursiveLock.swift +++ b/SwiftTask/_RecursiveLock.swift @@ -15,8 +15,8 @@ internal final class _RecursiveLock internal init() { - self.mutex = UnsafeMutablePointer.alloc(1) - self.attribute = UnsafeMutablePointer.alloc(1) + self.mutex = UnsafeMutablePointer(allocatingCapacity: 1) + self.attribute = UnsafeMutablePointer(allocatingCapacity: 1) pthread_mutexattr_init(self.attribute) pthread_mutexattr_settype(self.attribute, PTHREAD_MUTEX_RECURSIVE) @@ -28,8 +28,8 @@ internal final class _RecursiveLock pthread_mutexattr_destroy(self.attribute) pthread_mutex_destroy(self.mutex) - self.attribute.dealloc(1) - self.mutex.dealloc(1) + self.attribute.deallocateCapacity(1) + self.mutex.deallocateCapacity(1) } internal func lock() diff --git a/SwiftTask/_StateMachine.swift b/SwiftTask/_StateMachine.swift index 50f0fa9..7fe5797 100644 --- a/SwiftTask/_StateMachine.swift +++ b/SwiftTask/_StateMachine.swift @@ -30,10 +30,10 @@ internal class _StateMachine /// wrapper closure for `_initClosure` to invoke only once when started `.Running`, /// and will be set to `nil` afterward - internal var initResumeClosure: _Atomic<(Void -> Void)?> = _Atomic(nil) + internal var initResumeClosure: _Atomic<(() -> Void)?> = _Atomic(nil) private lazy var _progressTupleHandlers = _Handlers() - private lazy var _completionHandlers = _Handlers Void>() + private lazy var _completionHandlers = _Handlers<() -> Void>() private var _lock = _RecursiveLock() @@ -43,7 +43,7 @@ internal class _StateMachine self.state = _Atomic(paused ? .Paused : .Running) } - internal func addProgressTupleHandler(inout token: _HandlerToken?, _ progressTupleHandler: ProgressTupleHandler) -> Bool + @discardableResult internal func addProgressTupleHandler(_ token: inout _HandlerToken?, _ progressTupleHandler: ProgressTupleHandler) -> Bool { self._lock.lock() defer { self._lock.unlock() } @@ -57,7 +57,7 @@ internal class _StateMachine } } - internal func removeProgressTupleHandler(handlerToken: _HandlerToken?) -> Bool + @discardableResult internal func removeProgressTupleHandler(_ handlerToken: _HandlerToken?) -> Bool { self._lock.lock() defer { self._lock.unlock() } @@ -71,7 +71,7 @@ internal class _StateMachine } } - internal func addCompletionHandler(inout token: _HandlerToken?, _ completionHandler: Void -> Void) -> Bool + @discardableResult internal func addCompletionHandler(_ token: inout _HandlerToken?, _ completionHandler: () -> Void) -> Bool { self._lock.lock() defer { self._lock.unlock() } @@ -85,7 +85,7 @@ internal class _StateMachine } } - internal func removeCompletionHandler(handlerToken: _HandlerToken?) -> Bool + @discardableResult internal func removeCompletionHandler(_ handlerToken: _HandlerToken?) -> Bool { self._lock.lock() defer { self._lock.unlock() } @@ -99,7 +99,7 @@ internal class _StateMachine } } - internal func handleProgress(progress: Progress) + internal func handleProgress(_ progress: Progress) { self._lock.lock() defer { self._lock.unlock() } @@ -119,7 +119,7 @@ internal class _StateMachine } } - internal func handleFulfill(value: Value) + internal func handleFulfill(_ value: Value) { self._lock.lock() defer { self._lock.unlock() } @@ -131,7 +131,7 @@ internal class _StateMachine } } - internal func handleRejectInfo(errorInfo: ErrorInfo) + internal func handleRejectInfo(_ errorInfo: ErrorInfo) { self._lock.lock() defer { self._lock.unlock() } @@ -203,7 +203,7 @@ internal class _StateMachine } } - internal func handleCancel(error: Error? = nil) -> Bool + internal func handleCancel(_ error: Error? = nil) -> Bool { self._lock.lock() defer { self._lock.unlock() } @@ -244,14 +244,14 @@ internal struct _HandlerToken internal let key: Int } -internal struct _Handlers: SequenceType +internal struct _Handlers: Sequence { internal typealias KeyValue = (key: Int, value: T) private var currentKey: Int = 0 private var elements = [KeyValue]() - internal mutating func append(value: T) -> _HandlerToken + internal mutating func append(_ value: T) -> _HandlerToken { self.currentKey = self.currentKey &+ 1 @@ -260,11 +260,11 @@ internal struct _Handlers: SequenceType return _HandlerToken(key: self.currentKey) } - internal mutating func remove(token: _HandlerToken) -> T? + internal mutating func remove(_ token: _HandlerToken) -> T? { for i in 0..: SequenceType internal mutating func removeAll(keepCapacity: Bool = false) { - self.elements.removeAll(keepCapacity: keepCapacity) + self.elements.removeAll(keepingCapacity: keepCapacity) } - internal func generate() -> AnyGenerator + internal func makeIterator() -> AnyIterator { - return AnyGenerator(self.elements.map { $0.value }.generate()) + return AnyIterator(self.elements.map { $0.value }.makeIterator()) } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/RetainCycleTests.swift b/SwiftTaskTests/RetainCycleTests.swift index a075a09..b884bf8 100644 --- a/SwiftTaskTests/RetainCycleTests.swift +++ b/SwiftTaskTests/RetainCycleTests.swift @@ -11,7 +11,7 @@ import XCTest class Player { - var completionHandler: (Void -> Void)? + var completionHandler: (() -> Void)? init() { @@ -23,7 +23,7 @@ class Player // println("[deinit] \(self)") } - func doSomething(completion: (Void -> Void)? = nil) + func doSomething(completion: (() -> Void)? = nil) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100_000_000), dispatch_get_main_queue()) { /*[weak self] in */ @@ -227,4 +227,4 @@ class RetainCycleTests: _TestCase XCTAssertNil(self.task) XCTAssertNil(self.player) } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/_TestCase.swift b/SwiftTaskTests/_TestCase.swift index 64dd986..8a09449 100644 --- a/SwiftTaskTests/_TestCase.swift +++ b/SwiftTaskTests/_TestCase.swift @@ -35,7 +35,7 @@ class _TestCase: XCTestCase var isAsync: Bool { return false } - func perform(closure: Void -> Void) + func perform(closure: () -> Void) { if self.isAsync { Async.main(after: 0.01, block: closure) @@ -44,4 +44,4 @@ class _TestCase: XCTestCase closure() } } -} \ No newline at end of file +} From 75c3b807342e70cdc941f84870d8e78768c7deb9 Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Sun, 19 Jun 2016 17:29:07 -0700 Subject: [PATCH 10/24] Migrate SwiftTaskTests to Swift 3.0 --- SwiftTaskTests/AlamofireTests.swift | 22 +++--- SwiftTaskTests/BasicTests.swift | 4 +- SwiftTaskTests/MultipleErrorTypesTests.swift | 16 ++-- SwiftTaskTests/MultipleTasksTests.swift | 18 ++--- SwiftTaskTests/RemoveHandlerTests.swift | 6 +- SwiftTaskTests/RetainCycleTests.swift | 10 +-- SwiftTaskTests/SwiftTaskTests.swift | 78 ++++++++++---------- SwiftTaskTests/TypeInferenceTests.swift | 4 +- SwiftTaskTests/_InterruptableTask.swift | 6 +- SwiftTaskTests/_TestCase.swift | 4 +- 10 files changed, 84 insertions(+), 84 deletions(-) diff --git a/SwiftTaskTests/AlamofireTests.swift b/SwiftTaskTests/AlamofireTests.swift index 543442c..e33f4ed 100644 --- a/SwiftTaskTests/AlamofireTests.swift +++ b/SwiftTaskTests/AlamofireTests.swift @@ -16,7 +16,7 @@ class AlamofireTests: _TestCase func testFulfill() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let task = Task { progress, fulfill, reject, configure in @@ -46,7 +46,7 @@ class AlamofireTests: _TestCase func testReject() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let task = Task { progress, fulfill, reject, configure in @@ -86,12 +86,12 @@ class AlamofireTests: _TestCase func testProgress() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // define task let task = Task { progress, fulfill, reject, configure in - download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)) + download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in @@ -129,16 +129,16 @@ class AlamofireTests: _TestCase func testNSProgress() { - let expect = self.expectationWithDescription(#function) - let nsProgress = NSProgress(totalUnitCount: 100) + let expect = self.expectation(withDescription: #function) + let nsProgress = Foundation.Progress(totalUnitCount: 100) // define task let task = Task { progress, fulfill, reject, configure in - nsProgress.becomeCurrentWithPendingUnitCount(50) + nsProgress.becomeCurrent(withPendingUnitCount: 50) // NOTE: test with url which returns totalBytesExpectedToWrite != -1 - download(.GET, "http://httpbin.org/bytes/1024", destination: Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)) + download(.GET, "http://httpbin.org/bytes/1024", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) .response { (request, response, data, error) in @@ -176,11 +176,11 @@ class AlamofireTests: _TestCase // func testCancel() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let task = Task { progress, fulfill, reject, configure in - let downloadRequst = download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .DocumentDirectory, domain: .UserDomainMask)) + let downloadRequst = download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) .response { (request, response, data, error) in @@ -217,7 +217,7 @@ class AlamofireTests: _TestCase } // cancel after 1ms - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1_000_000), dispatch_get_main_queue()) { + DispatchQueue.main.after(when: .now() + 0.001) { task.cancel() // sends no error diff --git a/SwiftTaskTests/BasicTests.swift b/SwiftTaskTests/BasicTests.swift index 8e541b5..62b6ab7 100644 --- a/SwiftTaskTests/BasicTests.swift +++ b/SwiftTaskTests/BasicTests.swift @@ -16,7 +16,7 @@ class BasicTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // define task let task = Task { progress, fulfill, reject, configure in @@ -72,4 +72,4 @@ class BasicTests: _TestCase self.wait() } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/MultipleErrorTypesTests.swift b/SwiftTaskTests/MultipleErrorTypesTests.swift index 2574855..4b48a8e 100644 --- a/SwiftTaskTests/MultipleErrorTypesTests.swift +++ b/SwiftTaskTests/MultipleErrorTypesTests.swift @@ -26,7 +26,7 @@ class MultipleErrorTypesTests: _TestCase var flow = [Int]() // delayed task + counting flow 1 & 2 - func _task1(ok ok: Bool) -> Task1 + func _task1(ok: Bool) -> Task1 { return Task1 { progress, fulfill, reject, configure in print("[task1] start") @@ -43,7 +43,7 @@ class MultipleErrorTypesTests: _TestCase } // delayed task + counting flow 4 & 5 - func _task2(ok ok: Bool) -> Task2 + func _task2(ok: Bool) -> Task2 { return Task2 { progress, fulfill, reject, configure in print("[task2] start") @@ -61,7 +61,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_then() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) self._task1(ok: true) .then { value, errorInfo -> Task2 in @@ -87,7 +87,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) self._task1(ok: true) .success { value -> Task2 in @@ -113,7 +113,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) self._task1(ok: true) .success { value -> Task2 in @@ -151,7 +151,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType_conversion() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) self._task1(ok: true) .success { value -> Task in @@ -191,7 +191,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_failure() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) self._task1(ok: false) .failure { errorInfo -> Task in @@ -221,4 +221,4 @@ class MultipleErrorTypesTests: _TestCase self.wait() } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/MultipleTasksTests.swift b/SwiftTaskTests/MultipleTasksTests.swift index d9a237f..825ae71 100644 --- a/SwiftTaskTests/MultipleTasksTests.swift +++ b/SwiftTaskTests/MultipleTasksTests.swift @@ -34,7 +34,7 @@ class MultipleTasksTests: _TestCase { func testMultipleTasksTests_success1_success2_success3() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var flow = [Int]() @@ -59,7 +59,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_success2_failure3() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var flow = [Int]() @@ -75,7 +75,7 @@ class MultipleTasksTests: _TestCase task3()._mapError(WrappedError.ByTask3) } .on(failure: { error, isCancelled in - guard case let .Some(.ByTask3(error3)) = error else { + guard case let .some(.ByTask3(error3)) = error else { XCTFail("Wrong WrappedError.") return } @@ -89,7 +89,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_failure2_success3() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var flow = [Int]() @@ -105,7 +105,7 @@ class MultipleTasksTests: _TestCase task3()._mapError(WrappedError.ByTask3) } .on(failure: { error, isCancelled in - guard case let .Some(.ByTask2(error2)) = error else { + guard case let .some(.ByTask2(error2)) = error else { XCTFail("Wrong WrappedError.") return } @@ -119,7 +119,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_failure2_success3_wrapped() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var flow = [Int]() @@ -142,7 +142,7 @@ class MultipleTasksTests: _TestCase wrapped3() } .on(failure: { error, isCancelled in - guard case let .Some(.ByTask2(error2)) = error else { + guard case let .some(.ByTask2(error2)) = error else { XCTFail("Wrong WrappedError.") return } @@ -158,7 +158,7 @@ class MultipleTasksTests: _TestCase extension Task { /// Converts `Task<..., Error>` to `Task<..., WrappedError>`. - private func _mapError(f: Error -> WrappedError) -> Task + private func _mapError(_ f: (Error) -> WrappedError) -> Task { return self.failure { error, isCancelled -> Task in if let error = error { @@ -172,7 +172,7 @@ extension Task } } -private func wrappedErrorTask(task: () -> Task, f: E -> WrappedError) -> () -> Task { +private func wrappedErrorTask(_ task: () -> Task, f: (E) -> WrappedError) -> () -> Task { return { task()._mapError(f) } diff --git a/SwiftTaskTests/RemoveHandlerTests.swift b/SwiftTaskTests/RemoveHandlerTests.swift index 47fe13a..680e1d4 100644 --- a/SwiftTaskTests/RemoveHandlerTests.swift +++ b/SwiftTaskTests/RemoveHandlerTests.swift @@ -16,7 +16,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var latestProgressValue: Float? var canceller: AutoCanceller? = nil @@ -60,7 +60,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var canceller: AutoCanceller? = nil // define task @@ -103,4 +103,4 @@ class RemoveHandlerTests: _TestCase self.wait() } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/RetainCycleTests.swift b/SwiftTaskTests/RetainCycleTests.swift index b884bf8..810b95f 100644 --- a/SwiftTaskTests/RetainCycleTests.swift +++ b/SwiftTaskTests/RetainCycleTests.swift @@ -25,7 +25,7 @@ class Player func doSomething(completion: (() -> Void)? = nil) { - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100_000_000), dispatch_get_main_queue()) { /*[weak self] in */ + DispatchQueue.main.after(when: .now() + 0.001) { /*[weak self] in */ // NOTE: callback (either as argument or stored property) must be captured by dispatch_queue @@ -54,7 +54,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_notConfigured() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // // retain cycle: @@ -98,7 +98,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_configured() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // // retain cycle: @@ -144,7 +144,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_notConfigured() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // // retain cycle: @@ -186,7 +186,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_configured() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) // // retain cycle: diff --git a/SwiftTaskTests/SwiftTaskTests.swift b/SwiftTaskTests/SwiftTaskTests.swift index b7fedd6..4228ebc 100644 --- a/SwiftTaskTests/SwiftTaskTests.swift +++ b/SwiftTaskTests/SwiftTaskTests.swift @@ -70,7 +70,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -90,7 +90,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_failure() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -114,7 +114,7 @@ class SwiftTaskTests: _TestCase func testFulfill_failure_success() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -140,7 +140,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_fulfill() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -172,7 +172,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_reject() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -212,7 +212,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -244,7 +244,7 @@ class SwiftTaskTests: _TestCase func testReject_failure() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -266,7 +266,7 @@ class SwiftTaskTests: _TestCase func testReject_success_failure() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -292,7 +292,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_success() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -320,7 +320,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_fulfill() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -353,7 +353,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_reject() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -394,7 +394,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task { progress, fulfill, reject, configure in @@ -428,7 +428,7 @@ class SwiftTaskTests: _TestCase func testOn_success() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -450,7 +450,7 @@ class SwiftTaskTests: _TestCase func testOn_failure() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -479,7 +479,7 @@ class SwiftTaskTests: _TestCase func testProgress() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 Task { progress, fulfill, reject, configure in @@ -530,7 +530,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -559,7 +559,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -588,7 +588,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5, finalState: .Rejected) // 1st async task (5 progresses -> rejected) @@ -618,7 +618,7 @@ class SwiftTaskTests: _TestCase func testCancel() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) @@ -660,7 +660,7 @@ class SwiftTaskTests: _TestCase func testCancel_then_innerTask() { - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let task1 = _interruptableTask(progressCount: 5) @@ -707,7 +707,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) @@ -754,7 +754,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let task = _interruptableTask(progressCount: 5) weak var innerTask: _InterruptableTask? @@ -823,7 +823,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let maxTryCount = 3 let fulfilledTryCount = 2 var actualTryCount = 0 @@ -865,7 +865,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let maxTryCount = 3 var actualTryCount = 0 @@ -897,7 +897,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let maxTryCount = 3 var actualTryCount = 0 var progressCount = 0 @@ -943,7 +943,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let maxTryCount = 5 var actualTryCount = 0 @@ -957,7 +957,7 @@ class SwiftTaskTests: _TestCase Async.background(after: 0.1) { while isPaused { print("pausing...") - NSThread.sleepForTimeInterval(0.1) + Thread.sleep(forTimeInterval: 0.1) } Async.main(after: 0.2) { if actualTryCount < maxTryCount { @@ -1008,7 +1008,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) let maxTryCount = 3 var actualTryCount = 0 @@ -1077,7 +1077,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1135,7 +1135,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<5 { @@ -1183,7 +1183,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1240,7 +1240,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1252,7 +1252,7 @@ class SwiftTaskTests: _TestCase Async.background(after: SAFE_BG_FLAG_CHECK_DELAY) { while isPaused { - NSThread.sleepForTimeInterval(0.1) + Thread.sleep(forTimeInterval: 0.1) } Async.main { fulfill("OK \(i)") } } @@ -1312,7 +1312,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1357,7 +1357,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1398,7 +1398,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1455,7 +1455,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1467,7 +1467,7 @@ class SwiftTaskTests: _TestCase Async.background(after: SAFE_BG_FLAG_CHECK_DELAY) { while isPaused { - NSThread.sleepForTimeInterval(0.1) + Thread.sleep(forTimeInterval: 0.1) } Async.main { fulfill("OK \(i)") } @@ -1525,7 +1525,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectationWithDescription(#function) + let expect = self.expectation(withDescription: #function) var tasks: [Task] = Array() for i in 0..<10 { diff --git a/SwiftTaskTests/TypeInferenceTests.swift b/SwiftTaskTests/TypeInferenceTests.swift index 29936d5..1d7a263 100644 --- a/SwiftTaskTests/TypeInferenceTests.swift +++ b/SwiftTaskTests/TypeInferenceTests.swift @@ -25,7 +25,7 @@ class TypeInferenceTests: _TestCase XCTFail("Because of preceding failure-recovering, this failure should never be performed (just added for type-inference test)") return ["You", "shall", "not", "pass"] }.then { value, errorInfo -> String in - return value!.joinWithSeparator(" ") + return value!.joined(separator: " ") }.then { value, errorInfo -> Void in XCTAssertEqual(value!, "Looks good to me") return @@ -36,4 +36,4 @@ class TypeInferenceTests: _TestCase // // } } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/_InterruptableTask.swift b/SwiftTaskTests/_InterruptableTask.swift index caae07c..a689489 100644 --- a/SwiftTaskTests/_InterruptableTask.swift +++ b/SwiftTaskTests/_InterruptableTask.swift @@ -14,7 +14,7 @@ typealias _InterruptableTask = Task /// 2. Checks cancel & pause at t=0.4 /// 3. Invokes remaining `progressCount-progressCount/2` progresses at t=0.4~ (if not paused) /// 4. Either fulfills with "OK" or rejects with "ERROR" at t=0.4~ (if not paused) -func _interruptableTask(progressCount progressCount: Int, finalState: TaskState = .Fulfilled) -> _InterruptableTask +func _interruptableTask(progressCount: Int, finalState: TaskState = .Fulfilled) -> _InterruptableTask { return _InterruptableTask { progress, fulfill, reject, configure in @@ -37,7 +37,7 @@ func _interruptableTask(progressCount progressCount: Int, finalState: TaskState while isPaused { print("pausing...") - NSThread.sleepForTimeInterval(0.1) + Thread.sleep(forTimeInterval: 0.1) } for p in progressCount/2+1...progressCount { @@ -69,4 +69,4 @@ func _interruptableTask(progressCount progressCount: Int, finalState: TaskState } } -} \ No newline at end of file +} diff --git a/SwiftTaskTests/_TestCase.swift b/SwiftTaskTests/_TestCase.swift index 8a09449..0add691 100644 --- a/SwiftTaskTests/_TestCase.swift +++ b/SwiftTaskTests/_TestCase.swift @@ -26,9 +26,9 @@ class _TestCase: XCTestCase super.tearDown() } - func wait(timeout: NSTimeInterval = 3) + func wait(_ timeout: TimeInterval = 3) { - self.waitForExpectationsWithTimeout(timeout) { error in + self.waitForExpectations(withTimeout: timeout) { error in print("wait error = \(error)") } } From e0cab49738818d8ba901e9730d501fd401a03fc1 Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Sun, 19 Jun 2016 17:29:19 -0700 Subject: [PATCH 11/24] Migrate playgrounds to Swift 3.0 --- .../02-Async.playground/Contents.swift | 2 +- .../02-Async.playground/contents.xcplayground | 2 +- .../xcshareddata/SwiftTask.xcscmblueprint | 44 +++++++++++++++++++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 SwiftTask.xcworkspace/xcshareddata/SwiftTask.xcscmblueprint diff --git a/Playgrounds/02-Async.playground/Contents.swift b/Playgrounds/02-Async.playground/Contents.swift index c29824f..9a2dbcc 100644 --- a/Playgrounds/02-Async.playground/Contents.swift +++ b/Playgrounds/02-Async.playground/Contents.swift @@ -26,7 +26,7 @@ XCPSetExecutionShouldContinueIndefinitely() func asyncTask(value: String) -> MyTask { return MyTask { progress, fulfill, reject, configure in - dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 100_000_000), dispatch_get_main_queue()) { + DispatchQueue.main.after(when: .now() + 0.001) { fulfill(value) } } diff --git a/Playgrounds/02-Async.playground/contents.xcplayground b/Playgrounds/02-Async.playground/contents.xcplayground index 06828af..16f9952 100644 --- a/Playgrounds/02-Async.playground/contents.xcplayground +++ b/Playgrounds/02-Async.playground/contents.xcplayground @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/SwiftTask.xcworkspace/xcshareddata/SwiftTask.xcscmblueprint b/SwiftTask.xcworkspace/xcshareddata/SwiftTask.xcscmblueprint new file mode 100644 index 0000000..dd4c8a7 --- /dev/null +++ b/SwiftTask.xcworkspace/xcshareddata/SwiftTask.xcscmblueprint @@ -0,0 +1,44 @@ +{ + "DVTSourceControlWorkspaceBlueprintPrimaryRemoteRepositoryKey" : "DF9A3E2A3372F2EF94714F47B19B6C0DCBBF4AB9", + "DVTSourceControlWorkspaceBlueprintWorkingCopyRepositoryLocationsKey" : { + + }, + "DVTSourceControlWorkspaceBlueprintWorkingCopyStatesKey" : { + "67620B5EFA902936DF04070AF595B76AB0333747" : 0, + "8CCFBC236B2D99F3320873838535AF1EA5422AB1" : 0, + "2DDF1D4E528EDA8D8E5AF503BA5680A30604BD70" : 0, + "DF9A3E2A3372F2EF94714F47B19B6C0DCBBF4AB9" : 0 + }, + "DVTSourceControlWorkspaceBlueprintIdentifierKey" : "7E8DD0F4-4FF2-4828-A975-A2138CA295EF", + "DVTSourceControlWorkspaceBlueprintWorkingCopyPathsKey" : { + "67620B5EFA902936DF04070AF595B76AB0333747" : "SwiftTask\/Carthage\/Checkouts\/Alamofire\/", + "8CCFBC236B2D99F3320873838535AF1EA5422AB1" : "SwiftTask\/Carthage\/Checkouts\/Async\/", + "2DDF1D4E528EDA8D8E5AF503BA5680A30604BD70" : "SwiftTask\/Carthage\/Checkouts\/xcconfigs\/", + "DF9A3E2A3372F2EF94714F47B19B6C0DCBBF4AB9" : "SwiftTask\/" + }, + "DVTSourceControlWorkspaceBlueprintNameKey" : "SwiftTask", + "DVTSourceControlWorkspaceBlueprintVersion" : 204, + "DVTSourceControlWorkspaceBlueprintRelativePathToProjectKey" : "SwiftTask.xcworkspace", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoriesKey" : [ + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/mrackwitz\/xcconfigs.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "2DDF1D4E528EDA8D8E5AF503BA5680A30604BD70" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/Alamofire\/Alamofire.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "67620B5EFA902936DF04070AF595B76AB0333747" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/duemunk\/Async.git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "8CCFBC236B2D99F3320873838535AF1EA5422AB1" + }, + { + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryURLKey" : "https:\/\/github.com\/jordanekay\/SwiftTask", + "DVTSourceControlWorkspaceBlueprintRemoteRepositorySystemKey" : "com.apple.dt.Xcode.sourcecontrol.Git", + "DVTSourceControlWorkspaceBlueprintRemoteRepositoryIdentifierKey" : "DF9A3E2A3372F2EF94714F47B19B6C0DCBBF4AB9" + } + ] +} \ No newline at end of file From 50a92696cbabed4fe9cec6b610b0d17a4156ec90 Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Tue, 5 Jul 2016 17:36:33 -0700 Subject: [PATCH 12/24] Fix build for Xcode 8 beta 2 See https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160125/008074.html --- SwiftTask/SwiftTask.swift | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index 0afc6f2..77ebae3 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -491,12 +491,13 @@ public class Task: Cancellable, CustomStringConvertible public func success(_ canceller: inout C?, _ successClosure: (Value) -> Task) -> Task { + var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in let selfMachine = self._machine // NOTE: using `self._then()` + `selfMachine` instead of `self.then()` will reduce Task allocation - self._then(&canceller) { + self._then(&localCanceller) { if let value = selfMachine.value.rawValue { let innerTask = successClosure(value) _bindInnerTask(innerTask, newMachine, progress, fulfill, _reject, configure) @@ -548,11 +549,12 @@ public class Task: Cancellable, CustomStringConvertible public func failure(_ canceller: inout C?, _ failureClosure: (ErrorInfo) -> Task) -> Task { + var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in let selfMachine = self._machine - self._then(&canceller) { + self._then(&localCanceller) { if let value = selfMachine.value.rawValue { fulfill(value) } From bdebc528f74144ee6ab60b7f4cf996074de145e8 Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Thu, 4 Aug 2016 14:33:08 -0400 Subject: [PATCH 13/24] Update for Xcode 8 beta 4 --- SwiftTask/_RecursiveLock.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SwiftTask/_RecursiveLock.swift b/SwiftTask/_RecursiveLock.swift index 16bfc8d..08365d4 100644 --- a/SwiftTask/_RecursiveLock.swift +++ b/SwiftTask/_RecursiveLock.swift @@ -15,8 +15,8 @@ internal final class _RecursiveLock internal init() { - self.mutex = UnsafeMutablePointer(allocatingCapacity: 1) - self.attribute = UnsafeMutablePointer(allocatingCapacity: 1) + self.mutex = UnsafeMutablePointer.allocate(capacity: 1) + self.attribute = UnsafeMutablePointer.allocate(capacity: 1) pthread_mutexattr_init(self.attribute) pthread_mutexattr_settype(self.attribute, PTHREAD_MUTEX_RECURSIVE) @@ -28,8 +28,8 @@ internal final class _RecursiveLock pthread_mutexattr_destroy(self.attribute) pthread_mutex_destroy(self.mutex) - self.attribute.deallocateCapacity(1) - self.mutex.deallocateCapacity(1) + self.attribute.deallocate(capacity: 1) + self.mutex.deallocate(capacity: 1) } internal func lock() From 84978cb80ee5a0968d39109de1f820df07fe42c2 Mon Sep 17 00:00:00 2001 From: Jordan Kay Date: Mon, 15 Aug 2016 18:35:51 -0400 Subject: [PATCH 14/24] Update for Xcode 8 beta 6 --- SwiftTask/Cancellable.swift | 2 +- SwiftTask/SwiftTask.swift | 46 +++++++++++++++++------------------ SwiftTask/_Atomic.swift | 20 +++++++-------- SwiftTask/_StateMachine.swift | 2 +- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/SwiftTask/Cancellable.swift b/SwiftTask/Cancellable.swift index 6bfcd5b..d9cd581 100644 --- a/SwiftTask/Cancellable.swift +++ b/SwiftTask/Cancellable.swift @@ -19,7 +19,7 @@ public class Canceller: Cancellable { private var cancelHandler: (() -> Void)? - public required init(cancelHandler: () -> Void) + public required init(cancelHandler: @escaping () -> Void) { self.cancelHandler = cancelHandler } diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index 77ebae3..415eab2 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -57,7 +57,7 @@ public class TaskConfiguration } } -public class Task: Cancellable, CustomStringConvertible +open class Task: Cancellable, CustomStringConvertible { public typealias ProgressTuple = (oldProgress: Progress?, newProgress: Progress) public typealias ErrorInfo = (error: Error?, isCancelled: Bool) @@ -67,12 +67,12 @@ public class Task: Cancellable, CustomStringConvertible public typealias RejectHandler = (Error) -> Void public typealias Configuration = TaskConfiguration - public typealias PromiseInitClosure = (fulfill: FulfillHandler, reject: RejectHandler) -> Void - public typealias InitClosure = (progress: ProgressHandler, fulfill: FulfillHandler, reject: RejectHandler, configure: TaskConfiguration) -> Void + public typealias PromiseInitClosure = (_ fulfill: FulfillHandler, _ reject: RejectHandler) -> Void + public typealias InitClosure = (_ progress: ProgressHandler, _ fulfill: FulfillHandler, _ reject: RejectHandler, _ configure: TaskConfiguration) -> Void internal typealias _Machine = _StateMachine - internal typealias _InitClosure = (machine: _Machine, progress: ProgressHandler, fulfill: FulfillHandler, _reject: _RejectInfoHandler, configure: TaskConfiguration) -> Void + internal typealias _InitClosure = (_ machine: _Machine, _ progress: ProgressHandler, _ fulfill: FulfillHandler, _ _reject: _RejectInfoHandler, _ configure: TaskConfiguration) -> Void internal typealias _ProgressTupleHandler = (ProgressTuple) -> Void internal typealias _RejectInfoHandler = (ErrorInfo) -> Void @@ -97,7 +97,7 @@ public class Task: Cancellable, CustomStringConvertible public var name: String = "DefaultTask" - public var description: String + open var description: String { var valueString: String? @@ -134,7 +134,7 @@ public class Task: Cancellable, CustomStringConvertible let _initClosure: _InitClosure = { _, progress, fulfill, _reject, configure in // NOTE: don't expose rejectHandler with ErrorInfo (isCancelled) for public init - initClosure(progress: progress, fulfill: fulfill, reject: { error in _reject(ErrorInfo(error: Optional(error), isCancelled: false)) }, configure: configure) + initClosure(progress, fulfill, { error in _reject(ErrorInfo(error: Optional(error), isCancelled: false)) }, configure) } self.setup(weakified: weakified, paused: paused, _initClosure: _initClosure) @@ -194,7 +194,7 @@ public class Task: Cancellable, CustomStringConvertible public convenience init(promiseInitClosure: PromiseInitClosure) { self.init(initClosure: { progress, fulfill, reject, configure in - promiseInitClosure(fulfill: fulfill, reject: { error in reject(error) }) + promiseInitClosure(fulfill, { error in reject(error) }) }) } @@ -274,7 +274,7 @@ public class Task: Cancellable, CustomStringConvertible } } - _initClosure(machine: self_._machine, progress: progressHandler, fulfill: fulfillHandler, _reject: rejectInfoHandler, configure: self_._machine.configuration) + _initClosure(self_._machine, progressHandler, fulfillHandler, rejectInfoHandler, self_._machine.configuration) } @@ -356,13 +356,13 @@ public class Task: Cancellable, CustomStringConvertible /// - Note: `oldProgress` is always nil when `weakified = true` /// - Returns: Self (same `Task`) /// - @discardableResult public func progress(progressClosure: (ProgressTuple) -> Void) -> Self + @discardableResult public func progress(progressClosure: @escaping (ProgressTuple) -> Void) -> Self { var dummyCanceller: Canceller? = nil return self.progress(&dummyCanceller, progressClosure) } - public func progress(_ canceller: inout C?, _ progressClosure: (ProgressTuple) -> Void) -> Self + public func progress(_ canceller: inout C?, _ progressClosure: @escaping (ProgressTuple) -> Void) -> Self { var token: _HandlerToken? = nil self._machine.addProgressTupleHandler(&token, progressClosure) @@ -382,13 +382,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func then(thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task + @discardableResult public func then(thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) } - public func then(_ canceller: inout C?, _ thenClosure: (Value?, ErrorInfo?) -> Value2) -> Task + public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task { return self.then(&canceller) { (value, errorInfo) -> Task in return Task(value: thenClosure(value, errorInfo)) @@ -403,7 +403,7 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func then(thenClosure: (Value?, ErrorInfo?) -> Task) -> Task + public func then(thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) @@ -417,7 +417,7 @@ public class Task: Cancellable, CustomStringConvertible // /// - Returns: New `Task` /// - public func then(_ canceller: inout C?, _ thenClosure: (Value?, ErrorInfo?) -> Task) -> Task + public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task { return Task { [unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in @@ -439,7 +439,7 @@ public class Task: Cancellable, CustomStringConvertible } /// invokes `completionHandler` "now" or "in the future" - private func _then(_ canceller: inout C?, _ completionHandler: () -> Void) + private func _then(_ canceller: inout C?, _ completionHandler: @escaping () -> Void) { switch self.state { case .Fulfilled, .Rejected, .Cancelled: @@ -462,13 +462,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func success(successClosure: (Value) -> Value2) -> Task + @discardableResult public func success(successClosure: @escaping (Value) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) } - public func success(_ canceller: inout C?, _ successClosure: (Value) -> Value2) -> Task + public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Value2) -> Task { return self.success(&canceller) { (value: Value) -> Task in return Task(value: successClosure(value)) @@ -483,13 +483,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func success(successClosure: (Value) -> Task) -> Task + public func success(successClosure: @escaping (Value) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) } - public func success(_ canceller: inout C?, _ successClosure: (Value) -> Task) -> Task + public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Task) -> Task { var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in @@ -519,13 +519,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func failure(failureClosure: (ErrorInfo) -> Value) -> Task + @discardableResult public func failure(failureClosure: @escaping (ErrorInfo) -> Value) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) } - public func failure(_ canceller: inout C?, _ failureClosure: (ErrorInfo) -> Value) -> Task + public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Value) -> Task { return self.failure(&canceller) { (errorInfo: ErrorInfo) -> Task in return Task(value: failureClosure(errorInfo)) @@ -541,13 +541,13 @@ public class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func failure(failureClosure: (ErrorInfo) -> Task) -> Task + public func failure(failureClosure: @escaping (ErrorInfo) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) } - public func failure(_ canceller: inout C?, _ failureClosure: (ErrorInfo) -> Task) -> Task + public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Task) -> Task { var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in diff --git a/SwiftTask/_Atomic.swift b/SwiftTask/_Atomic.swift index 6001143..cf48b9f 100644 --- a/SwiftTask/_Atomic.swift +++ b/SwiftTask/_Atomic.swift @@ -11,14 +11,14 @@ import Darwin internal final class _Atomic { private var _spinlock = OS_SPINLOCK_INIT - private var _rawValue: T + fileprivate var _rawValue: T internal init(_ rawValue: T) { self._rawValue = rawValue } - internal func withRawValue(_ f: @noescape (T) -> U) -> U + internal func withRawValue(_ f: (T) -> U) -> U { self._lock() defer { self._unlock() } @@ -26,17 +26,17 @@ internal final class _Atomic return f(self._rawValue) } - internal func update(_ f: @noescape (T) -> T) -> T + internal func update(_ f: (T) -> T) -> T { return self.updateIf { f($0) }! } - internal func updateIf(_ f: @noescape (T) -> T?) -> T? + internal func updateIf(_ f: (T) -> T?) -> T? { return self.modify { value in f(value).map { ($0, value) } } } - internal func modify(_ f: @noescape (T) -> (T, U)?) -> U? + internal func modify(_ f: (T) -> (T, U)?) -> U? { self._lock() defer { self._unlock() } @@ -51,14 +51,14 @@ internal final class _Atomic } } - private func _lock() + fileprivate func _lock() { - withUnsafeMutablePointer(&self._spinlock, OSSpinLockLock) + withUnsafeMutablePointer(to: &self._spinlock, OSSpinLockLock) } - private func _unlock() + fileprivate func _unlock() { - withUnsafeMutablePointer(&self._spinlock, OSSpinLockUnlock) + withUnsafeMutablePointer(to: &self._spinlock, OSSpinLockUnlock) } } @@ -91,6 +91,6 @@ extension _Atomic: CustomStringConvertible { internal var description: String { - return String(self.rawValue) + return String(describing: self.rawValue) } } diff --git a/SwiftTask/_StateMachine.swift b/SwiftTask/_StateMachine.swift index 7fe5797..56ab101 100644 --- a/SwiftTask/_StateMachine.swift +++ b/SwiftTask/_StateMachine.swift @@ -71,7 +71,7 @@ internal class _StateMachine } } - @discardableResult internal func addCompletionHandler(_ token: inout _HandlerToken?, _ completionHandler: () -> Void) -> Bool + @discardableResult internal func addCompletionHandler(_ token: inout _HandlerToken?, _ completionHandler: @escaping () -> Void) -> Bool { self._lock.lock() defer { self._lock.unlock() } From e5778962462e25e38f2a3bffe5127cbaec7fe989 Mon Sep 17 00:00:00 2001 From: Jin Wang Date: Thu, 8 Sep 2016 17:21:39 +1000 Subject: [PATCH 15/24] Updated for Xcode 8 GM. --- SwiftTask/SwiftTask.swift | 22 +++++++++++----------- SwiftTask/_StateMachine.swift | 2 +- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index 415eab2..de172bb 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -68,11 +68,11 @@ open class Task: Cancellable, CustomStringConvertible public typealias Configuration = TaskConfiguration public typealias PromiseInitClosure = (_ fulfill: FulfillHandler, _ reject: RejectHandler) -> Void - public typealias InitClosure = (_ progress: ProgressHandler, _ fulfill: FulfillHandler, _ reject: RejectHandler, _ configure: TaskConfiguration) -> Void + public typealias InitClosure = (_ progress: @escaping ProgressHandler, _ fulfill: @escaping FulfillHandler, _ reject: @escaping RejectHandler, _ configure: TaskConfiguration) -> Void internal typealias _Machine = _StateMachine - internal typealias _InitClosure = (_ machine: _Machine, _ progress: ProgressHandler, _ fulfill: FulfillHandler, _ _reject: _RejectInfoHandler, _ configure: TaskConfiguration) -> Void + internal typealias _InitClosure = (_ machine: _Machine, _ progress: @escaping ProgressHandler, _ fulfill: @escaping FulfillHandler, _ _reject: @escaping _RejectInfoHandler, _ configure: TaskConfiguration) -> Void internal typealias _ProgressTupleHandler = (ProgressTuple) -> Void internal typealias _RejectInfoHandler = (ErrorInfo) -> Void @@ -126,7 +126,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New task. /// - public init(weakified: Bool, paused: Bool, initClosure: InitClosure) + public init(weakified: Bool, paused: Bool, initClosure: @escaping InitClosure) { self._weakified = weakified self._paused = paused @@ -145,7 +145,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - e.g. Task(paused: false) { progress, fulfill, reject, configure in ... } /// - public convenience init(paused: Bool, initClosure: InitClosure) + public convenience init(paused: Bool, initClosure: @escaping InitClosure) { self.init(weakified: false, paused: paused, initClosure: initClosure) } @@ -155,7 +155,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - e.g. Task { progress, fulfill, reject, configure in ... } /// - public convenience init(initClosure: InitClosure) + public convenience init(initClosure: @escaping InitClosure) { self.init(weakified: false, paused: false, initClosure: initClosure) } @@ -191,7 +191,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - e.g. Task { fulfill, reject in ... } /// - public convenience init(promiseInitClosure: PromiseInitClosure) + public convenience init(promiseInitClosure: @escaping PromiseInitClosure) { self.init(initClosure: { progress, fulfill, reject, configure in promiseInitClosure(fulfill, { error in reject(error) }) @@ -200,7 +200,7 @@ open class Task: Cancellable, CustomStringConvertible /// internal-init for accessing `machine` inside `_initClosure` /// (NOTE: _initClosure has _RejectInfoHandler as argument) - internal init(weakified: Bool = false, paused: Bool = false, _initClosure: _InitClosure) + internal init(weakified: Bool = false, paused: Bool = false, _initClosure: @escaping _InitClosure) { self._weakified = weakified self._paused = paused @@ -210,7 +210,7 @@ open class Task: Cancellable, CustomStringConvertible } // NOTE: don't use `internal init` for this setup method, or this will be a designated initializer - internal func setup(weakified: Bool, paused: Bool, _initClosure: _InitClosure) + internal func setup(weakified: Bool, paused: Bool, _initClosure: @escaping _InitClosure) { // #if DEBUG // let addr = String(format: "%p", unsafeAddressOf(self)) @@ -620,9 +620,9 @@ open class Task: Cancellable, CustomStringConvertible internal func _bindInnerTask( _ innerTask: Task, _ newMachine: _StateMachine, - _ progress: Task.ProgressHandler, - _ fulfill: Task.FulfillHandler, - _ _reject: Task._RejectInfoHandler, + _ progress: @escaping Task.ProgressHandler, + _ fulfill: @escaping Task.FulfillHandler, + _ _reject: @escaping Task._RejectInfoHandler, _ configure: TaskConfiguration ) { diff --git a/SwiftTask/_StateMachine.swift b/SwiftTask/_StateMachine.swift index 56ab101..1a19b1e 100644 --- a/SwiftTask/_StateMachine.swift +++ b/SwiftTask/_StateMachine.swift @@ -43,7 +43,7 @@ internal class _StateMachine self.state = _Atomic(paused ? .Paused : .Running) } - @discardableResult internal func addProgressTupleHandler(_ token: inout _HandlerToken?, _ progressTupleHandler: ProgressTupleHandler) -> Bool + @discardableResult internal func addProgressTupleHandler(_ token: inout _HandlerToken?, _ progressTupleHandler: @escaping ProgressTupleHandler) -> Bool { self._lock.lock() defer { self._lock.unlock() } From 80a3e4a40e33812d0535b6828f0d7821e301b980 Mon Sep 17 00:00:00 2001 From: KevM Date: Thu, 22 Sep 2016 11:16:49 -0500 Subject: [PATCH 16/24] Make PromiseInitClosure @escaping Seeing this error when using `PromiseInitClosure`: > Closure use of non-escaping parameter 'fulfill' may allow it to escape --- SwiftTask/SwiftTask.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index de172bb..6951e54 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -67,7 +67,7 @@ open class Task: Cancellable, CustomStringConvertible public typealias RejectHandler = (Error) -> Void public typealias Configuration = TaskConfiguration - public typealias PromiseInitClosure = (_ fulfill: FulfillHandler, _ reject: RejectHandler) -> Void + public typealias PromiseInitClosure = (_ fulfill: @escaping FulfillHandler, _ reject: @escaping RejectHandler) -> Void public typealias InitClosure = (_ progress: @escaping ProgressHandler, _ fulfill: @escaping FulfillHandler, _ reject: @escaping RejectHandler, _ configure: TaskConfiguration) -> Void internal typealias _Machine = _StateMachine From 3a81e29cdff89c64f43a1c0637fef496dca848ec Mon Sep 17 00:00:00 2001 From: KevM Date: Thu, 22 Sep 2016 11:18:58 -0500 Subject: [PATCH 17/24] Backwards compatible labels Added _ to closure arguments to make public methods backwards compatible. --- SwiftTask/SwiftTask.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index 6951e54..cb4d163 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -356,7 +356,7 @@ open class Task: Cancellable, CustomStringConvertible /// - Note: `oldProgress` is always nil when `weakified = true` /// - Returns: Self (same `Task`) /// - @discardableResult public func progress(progressClosure: @escaping (ProgressTuple) -> Void) -> Self + @discardableResult public func progress(_ progressClosure: @escaping (ProgressTuple) -> Void) -> Self { var dummyCanceller: Canceller? = nil return self.progress(&dummyCanceller, progressClosure) @@ -382,7 +382,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func then(thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task + @discardableResult public func then(_ thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) @@ -403,7 +403,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func then(thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task + public func then(_ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) @@ -462,7 +462,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func success(successClosure: @escaping (Value) -> Value2) -> Task + @discardableResult public func success(_ successClosure: @escaping (Value) -> Value2) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) @@ -483,7 +483,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func success(successClosure: @escaping (Value) -> Task) -> Task + public func success(_ successClosure: @escaping (Value) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) @@ -519,7 +519,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - @discardableResult public func failure(failureClosure: @escaping (ErrorInfo) -> Value) -> Task + @discardableResult public func failure(_ failureClosure: @escaping (ErrorInfo) -> Value) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) @@ -541,7 +541,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func failure(failureClosure: @escaping (ErrorInfo) -> Task) -> Task + public func failure(_ failureClosure: @escaping (ErrorInfo) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) From 98f89883509d27229d60ff3f2ececdd82a46d674 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Sun, 25 Sep 2016 19:30:33 +0900 Subject: [PATCH 18/24] [Test] Update to Swift 3 syntax, removing Alamofire --- .gitmodules | 3 - Cartfile.private | 5 +- Cartfile.resolved | 3 +- Carthage/Checkouts/Alamofire | 1 - Carthage/Checkouts/Async | 2 +- Configurations/Base.xcconfig | 4 +- SwiftTask.xcodeproj/project.pbxproj | 22 +++--- .../contents.xcworkspacedata | 7 -- SwiftTaskTests/AlamofireTests.swift | 79 +++++++++---------- SwiftTaskTests/BasicTests.swift | 2 +- SwiftTaskTests/MultipleErrorTypesTests.swift | 10 +-- SwiftTaskTests/MultipleTasksTests.swift | 18 ++--- SwiftTaskTests/RemoveHandlerTests.swift | 4 +- SwiftTaskTests/RetainCycleTests.swift | 10 +-- SwiftTaskTests/SwiftTaskTests.swift | 72 ++++++++--------- SwiftTaskTests/_TestCase.swift | 6 +- 16 files changed, 113 insertions(+), 135 deletions(-) delete mode 160000 Carthage/Checkouts/Alamofire diff --git a/.gitmodules b/.gitmodules index 24a5442..6cb82e9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "Carthage/Checkouts/Alamofire"] - path = Carthage/Checkouts/Alamofire - url = https://github.com/Alamofire/Alamofire.git [submodule "Carthage/Checkouts/Async"] path = Carthage/Checkouts/Async url = https://github.com/duemunk/Async.git diff --git a/Cartfile.private b/Cartfile.private index 4238969..55a867d 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,2 @@ -github "Alamofire/Alamofire" "swift3" -github "duemunk/Async" "feature/Swift_3.0" -github "mrackwitz/xcconfigs" \ No newline at end of file +github "duemunk/Async" +github "mrackwitz/xcconfigs" diff --git a/Cartfile.resolved b/Cartfile.resolved index 88415de..41e0e6e 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,3 +1,2 @@ -github "Alamofire/Alamofire" "e891699312a5215ad0da9f8322c5da949f90db35" -github "duemunk/Async" "23d32df500f7ace6ea1526e7433a0fa7004c8d7d" +github "duemunk/Async" "2.0.0" github "mrackwitz/xcconfigs" "3.0" diff --git a/Carthage/Checkouts/Alamofire b/Carthage/Checkouts/Alamofire deleted file mode 160000 index e891699..0000000 --- a/Carthage/Checkouts/Alamofire +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e891699312a5215ad0da9f8322c5da949f90db35 diff --git a/Carthage/Checkouts/Async b/Carthage/Checkouts/Async index 23d32df..be84110 160000 --- a/Carthage/Checkouts/Async +++ b/Carthage/Checkouts/Async @@ -1 +1 @@ -Subproject commit 23d32df500f7ace6ea1526e7433a0fa7004c8d7d +Subproject commit be84110aa5e7852c5e577d3bd6902177c6742512 diff --git a/Configurations/Base.xcconfig b/Configurations/Base.xcconfig index 3f5769a..4b8280d 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 = 3.0; diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index 8d867ab..85dfdaa 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -15,8 +15,6 @@ 1F46DEDA199EDF1000F97868 /* SwiftTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 1F46DED9199EDF1000F97868 /* SwiftTask.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1F46DEFB199EDF8100F97868 /* SwiftTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFA199EDF8100F97868 /* SwiftTask.swift */; }; 1F46DEFD199EE2C200F97868 /* _TestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEFC199EE2C200F97868 /* _TestCase.swift */; }; - 1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */; }; - 1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */; }; 1F4C7AD71B7CD27200DEB1AE /* Async.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F4C7AD61B7CD27100DEB1AE /* Async.framework */; }; 1F4C7AD91B7CD27600DEB1AE /* Async.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F4C7AD81B7CD27600DEB1AE /* Async.framework */; }; 1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEE3199EDF1000F97868 /* SwiftTaskTests.swift */; }; @@ -123,6 +121,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1F1BFFE21D97DCD9000105EB /* Deprecated */ = { + isa = PBXGroup; + children = ( + 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */, + ); + name = Deprecated; + sourceTree = ""; + }; 1F46DECA199EDF1000F97868 = { isa = PBXGroup; children = ( @@ -175,9 +181,9 @@ 48511C5A19C17563002FE03C /* RetainCycleTests.swift */, 485C31F01A1D619A00040DA3 /* TypeInferenceTests.swift */, 1F218D5A1AFC3FFD00C849FF /* RemoveHandlerTests.swift */, - 1F5FA35619A374E600975FB9 /* AlamofireTests.swift */, 1F29F6411B115EF500F476AF /* MultipleErrorTypesTests.swift */, 1FF95CAF1CDD8F8D00899FEA /* MultipleTasksTests.swift */, + 1F1BFFE21D97DCD9000105EB /* Deprecated */, 1F46DEE1199EDF1000F97868 /* Supporting Files */, ); path = SwiftTaskTests; @@ -384,7 +390,6 @@ 1FF95CB01CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */, 1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */, 1F29F6421B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */, - 1F4C76A41AD8CF40004E47C1 /* AlamofireTests.swift in Sources */, 485C31F11A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */, 48511C5B19C17563002FE03C /* RetainCycleTests.swift in Sources */, 1F46DEFD199EE2C200F97868 /* _TestCase.swift in Sources */, @@ -401,7 +406,6 @@ 1FF95CB11CDD8F8D00899FEA /* MultipleTasksTests.swift in Sources */, 1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */, 1F29F6431B115EF500F476AF /* MultipleErrorTypesTests.swift in Sources */, - 1F4C76A51AD8CF41004E47C1 /* AlamofireTests.swift in Sources */, 485C31F21A1D619A00040DA3 /* TypeInferenceTests.swift in Sources */, 4822F0DC19D00B2300F5F572 /* _TestCase.swift in Sources */, 4822F0E019D00B2300F5F572 /* RetainCycleTests.swift in Sources */, @@ -522,7 +526,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -542,7 +545,6 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 3.0; }; name = Release; }; @@ -556,11 +558,9 @@ "$(inherited)", ); INFOPLIST_FILE = SwiftTaskTests/Info.plist; - MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -570,11 +570,9 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = SwiftTaskTests/Info.plist; - MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - SWIFT_VERSION = 3.0; }; name = Release; }; @@ -587,7 +585,6 @@ "$(inherited)", ); INFOPLIST_FILE = SwiftTaskTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -599,7 +596,6 @@ baseConfigurationReference = 1FFADCDE1C5CEC1B000B66BE /* UniversalFramework_Test.xcconfig */; buildSettings = { INFOPLIST_FILE = SwiftTaskTests/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; diff --git a/SwiftTask.xcworkspace/contents.xcworkspacedata b/SwiftTask.xcworkspace/contents.xcworkspacedata index f41a4db..71cfca0 100644 --- a/SwiftTask.xcworkspace/contents.xcworkspacedata +++ b/SwiftTask.xcworkspace/contents.xcworkspacedata @@ -24,13 +24,6 @@ location = "group:Async.xcodeproj"> - - - - diff --git a/SwiftTaskTests/AlamofireTests.swift b/SwiftTaskTests/AlamofireTests.swift index e33f4ed..00a66e4 100644 --- a/SwiftTaskTests/AlamofireTests.swift +++ b/SwiftTaskTests/AlamofireTests.swift @@ -12,18 +12,18 @@ import XCTest class AlamofireTests: _TestCase { - typealias Progress = (bytesWritten: Int64, totalBytesWritten: Int64, totalBytesExpectedToWrite: Int64) + typealias Progress = Double func testFulfill() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) - let task = Task { progress, fulfill, reject, configure in - - request(.GET, "http://httpbin.org/get", parameters: ["foo": "bar"]) - .response { (request, response, data, error) in + let task = Task { progress, fulfill, reject, configure in + + Alamofire.request("http://httpbin.org/get", method: .get, parameters: ["foo": "bar"]) + .response { response in - if let error = error { + if let error = response.error { reject(error) return } @@ -46,21 +46,21 @@ class AlamofireTests: _TestCase func testReject() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) - let task = Task { progress, fulfill, reject, configure in + let task = Task { progress, fulfill, reject, configure in let dummyURLString = "http://xxx-swift-task.org/get" - request(.GET, dummyURLString, parameters: ["foo": "bar"]) - .response { (request, response, data, error) in + Alamofire.request(dummyURLString, method: .get, parameters: ["foo": "bar"]) + .response { response in - if let error = error { + if let error = response.error { reject(error) // pass non-nil error return } - if response?.statusCode >= 300 { + if let status = response.response?.statusCode, status >= 300 { reject(NSError(domain: "", code: 0, userInfo: nil)) } @@ -74,7 +74,7 @@ class AlamofireTests: _TestCase XCTFail("Should never reach here.") - }.failure { (error: NSError?, isCancelled: Bool) -> Void in + }.failure { (error: Error?, isCancelled: Bool) -> Void in XCTAssertTrue(error != nil, "Should receive non-nil error.") expect.fulfill() @@ -86,20 +86,20 @@ class AlamofireTests: _TestCase func testProgress() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // define task - let task = Task { progress, fulfill, reject, configure in + let task = Task { progress, fulfill, reject, configure in - download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) + Alamofire.download("http://httpbin.org/stream/100", method: .get, to: DownloadRequest.suggestedDownloadDestination()) - .progress { (bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) in - - progress((bytesWritten, totalBytesWritten, totalBytesExpectedToWrite) as Progress) + .downloadProgress { progress_ in + + progress(progress_.fractionCompleted) - }.response { (request, response, data, error) in + }.response { response in - if let error = error { + if let error = response.error { reject(error) return } @@ -113,13 +113,8 @@ class AlamofireTests: _TestCase } // set progress & then - task.progress { _, progress in - - print("bytesWritten = \(progress.bytesWritten)") - print("totalBytesWritten = \(progress.totalBytesWritten)") - print("totalBytesExpectedToWrite = \(progress.totalBytesExpectedToWrite)") - print("") - + task.progress { _, progress_ in + print("progress = \(progress_)") }.then { value, errorInfo -> Void in expect.fulfill() } @@ -129,20 +124,19 @@ class AlamofireTests: _TestCase func testNSProgress() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let nsProgress = Foundation.Progress(totalUnitCount: 100) // define task - let task = Task { progress, fulfill, reject, configure in + let task = Task { progress, fulfill, reject, configure in nsProgress.becomeCurrent(withPendingUnitCount: 50) // NOTE: test with url which returns totalBytesExpectedToWrite != -1 - download(.GET, "http://httpbin.org/bytes/1024", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) - - .response { (request, response, data, error) in + Alamofire.download("http://httpbin.org/bytes/1024", method: .get, to: DownloadRequest.suggestedDownloadDestination()) + .response { response in - if let error = error { + if let error = response.error { reject(error) return } @@ -176,15 +170,14 @@ class AlamofireTests: _TestCase // func testCancel() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) - let task = Task { progress, fulfill, reject, configure in + let task = Task { progress, fulfill, reject, configure in - let downloadRequst = download(.GET, "http://httpbin.org/stream/100", destination: Request.suggestedDownloadDestination(directory: .documentDirectory, domain: .userDomainMask)) - - .response { (request, response, data, error) in + let downloadRequst = Alamofire.download("http://httpbin.org/stream/100", method: .get, to: DownloadRequest.suggestedDownloadDestination()) + .response { response in - if let error = error { + if let error = response.error { reject(error) return } @@ -207,7 +200,7 @@ class AlamofireTests: _TestCase XCTFail("Should never reach here because task is cancelled.") - }.failure { (error: NSError?, isCancelled: Bool) -> Void in + }.failure { (error: Error?, isCancelled: Bool) -> Void in XCTAssertTrue(error == nil, "Should receive nil error via task.cancel().") XCTAssertTrue(isCancelled) @@ -217,7 +210,7 @@ class AlamofireTests: _TestCase } // cancel after 1ms - DispatchQueue.main.after(when: .now() + 0.001) { + DispatchQueue.main.asyncAfter(deadline: .now() + 0.001) { task.cancel() // sends no error diff --git a/SwiftTaskTests/BasicTests.swift b/SwiftTaskTests/BasicTests.swift index 62b6ab7..8f8981d 100644 --- a/SwiftTaskTests/BasicTests.swift +++ b/SwiftTaskTests/BasicTests.swift @@ -16,7 +16,7 @@ class BasicTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // define task let task = Task { progress, fulfill, reject, configure in diff --git a/SwiftTaskTests/MultipleErrorTypesTests.swift b/SwiftTaskTests/MultipleErrorTypesTests.swift index 4b48a8e..778f1f6 100644 --- a/SwiftTaskTests/MultipleErrorTypesTests.swift +++ b/SwiftTaskTests/MultipleErrorTypesTests.swift @@ -61,7 +61,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_then() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) self._task1(ok: true) .then { value, errorInfo -> Task2 in @@ -87,7 +87,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) self._task1(ok: true) .success { value -> Task2 in @@ -113,7 +113,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) self._task1(ok: true) .success { value -> Task2 in @@ -151,7 +151,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_success_differentErrorType_conversion() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) self._task1(ok: true) .success { value -> Task in @@ -191,7 +191,7 @@ class MultipleErrorTypesTests: _TestCase func testMultipleErrorTypes_failure() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) self._task1(ok: false) .failure { errorInfo -> Task in diff --git a/SwiftTaskTests/MultipleTasksTests.swift b/SwiftTaskTests/MultipleTasksTests.swift index 825ae71..add1197 100644 --- a/SwiftTaskTests/MultipleTasksTests.swift +++ b/SwiftTaskTests/MultipleTasksTests.swift @@ -34,7 +34,7 @@ class MultipleTasksTests: _TestCase { func testMultipleTasksTests_success1_success2_success3() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var flow = [Int]() @@ -59,7 +59,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_success2_failure3() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var flow = [Int]() @@ -89,7 +89,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_failure2_success3() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var flow = [Int]() @@ -119,7 +119,7 @@ class MultipleTasksTests: _TestCase func testMultipleTasksTests_success1_failure2_success3_wrapped() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var flow = [Int]() @@ -158,7 +158,7 @@ class MultipleTasksTests: _TestCase extension Task { /// Converts `Task<..., Error>` to `Task<..., WrappedError>`. - private func _mapError(_ f: (Error) -> WrappedError) -> Task + fileprivate func _mapError(_ f: @escaping (Error) -> WrappedError) -> Task { return self.failure { error, isCancelled -> Task in if let error = error { @@ -172,8 +172,8 @@ extension Task } } -private func wrappedErrorTask(_ task: () -> Task, f: (E) -> WrappedError) -> () -> Task { - return { - task()._mapError(f) - } +private func wrappedErrorTask(_ task: @escaping () -> Task, f: @escaping (E) -> WrappedError) -> () -> Task { + return { + task()._mapError(f) + } } diff --git a/SwiftTaskTests/RemoveHandlerTests.swift b/SwiftTaskTests/RemoveHandlerTests.swift index 680e1d4..1ced127 100644 --- a/SwiftTaskTests/RemoveHandlerTests.swift +++ b/SwiftTaskTests/RemoveHandlerTests.swift @@ -16,7 +16,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var latestProgressValue: Float? var canceller: AutoCanceller? = nil @@ -60,7 +60,7 @@ class RemoveHandlerTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var canceller: AutoCanceller? = nil // define task diff --git a/SwiftTaskTests/RetainCycleTests.swift b/SwiftTaskTests/RetainCycleTests.swift index 810b95f..92b7542 100644 --- a/SwiftTaskTests/RetainCycleTests.swift +++ b/SwiftTaskTests/RetainCycleTests.swift @@ -25,7 +25,7 @@ class Player func doSomething(completion: (() -> Void)? = nil) { - DispatchQueue.main.after(when: .now() + 0.001) { /*[weak self] in */ + DispatchQueue.main.asyncAfter(deadline: .now() + 0.001) { /*[weak self] in */ // NOTE: callback (either as argument or stored property) must be captured by dispatch_queue @@ -54,7 +54,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_notConfigured() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // // retain cycle: @@ -98,7 +98,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsArgument_configured() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // // retain cycle: @@ -144,7 +144,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_notConfigured() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // // retain cycle: @@ -186,7 +186,7 @@ class RetainCycleTests: _TestCase func testPlayer_completionAsStoredProperty_configured() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) // // retain cycle: diff --git a/SwiftTaskTests/SwiftTaskTests.swift b/SwiftTaskTests/SwiftTaskTests.swift index 4228ebc..c412ce6 100644 --- a/SwiftTaskTests/SwiftTaskTests.swift +++ b/SwiftTaskTests/SwiftTaskTests.swift @@ -70,7 +70,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -90,7 +90,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_failure() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -114,7 +114,7 @@ class SwiftTaskTests: _TestCase func testFulfill_failure_success() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -140,7 +140,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_fulfill() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -172,7 +172,7 @@ class SwiftTaskTests: _TestCase func testFulfill_success_innerTask_reject() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -212,7 +212,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -244,7 +244,7 @@ class SwiftTaskTests: _TestCase func testReject_failure() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -266,7 +266,7 @@ class SwiftTaskTests: _TestCase func testReject_success_failure() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -292,7 +292,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_success() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -320,7 +320,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_fulfill() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -353,7 +353,7 @@ class SwiftTaskTests: _TestCase func testReject_failure_innerTask_reject() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -394,7 +394,7 @@ class SwiftTaskTests: _TestCase { typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task { progress, fulfill, reject, configure in @@ -428,7 +428,7 @@ class SwiftTaskTests: _TestCase func testOn_success() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -450,7 +450,7 @@ class SwiftTaskTests: _TestCase func testOn_failure() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) Task<(), String, ErrorString> { progress, fulfill, reject, configure in @@ -479,7 +479,7 @@ class SwiftTaskTests: _TestCase func testProgress() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 Task { progress, fulfill, reject, configure in @@ -530,7 +530,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -559,7 +559,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) @@ -588,7 +588,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5, finalState: .Rejected) // 1st async task (5 progresses -> rejected) @@ -618,7 +618,7 @@ class SwiftTaskTests: _TestCase func testCancel() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) @@ -660,7 +660,7 @@ class SwiftTaskTests: _TestCase func testCancel_then_innerTask() { - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let task1 = _interruptableTask(progressCount: 5) @@ -707,7 +707,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var progressCount = 0 let task = _interruptableTask(progressCount: 5) @@ -754,7 +754,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let task = _interruptableTask(progressCount: 5) weak var innerTask: _InterruptableTask? @@ -823,7 +823,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let maxTryCount = 3 let fulfilledTryCount = 2 var actualTryCount = 0 @@ -865,7 +865,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let maxTryCount = 3 var actualTryCount = 0 @@ -897,7 +897,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let maxTryCount = 3 var actualTryCount = 0 var progressCount = 0 @@ -943,7 +943,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let maxTryCount = 5 var actualTryCount = 0 @@ -1008,7 +1008,7 @@ class SwiftTaskTests: _TestCase // NOTE: this is async test if !self.isAsync { return } - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) let maxTryCount = 3 var actualTryCount = 0 @@ -1077,7 +1077,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1135,7 +1135,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<5 { @@ -1183,7 +1183,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1240,7 +1240,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1312,7 +1312,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1357,7 +1357,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1398,7 +1398,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1455,7 +1455,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { @@ -1525,7 +1525,7 @@ class SwiftTaskTests: _TestCase typealias Task = SwiftTask.Task - let expect = self.expectation(withDescription: #function) + let expect = self.expectation(description: #function) var tasks: [Task] = Array() for i in 0..<10 { diff --git a/SwiftTaskTests/_TestCase.swift b/SwiftTaskTests/_TestCase.swift index 0add691..0c21690 100644 --- a/SwiftTaskTests/_TestCase.swift +++ b/SwiftTaskTests/_TestCase.swift @@ -28,17 +28,17 @@ class _TestCase: XCTestCase func wait(_ timeout: TimeInterval = 3) { - self.waitForExpectations(withTimeout: timeout) { error in + self.waitForExpectations(timeout: timeout) { error in print("wait error = \(error)") } } var isAsync: Bool { return false } - func perform(closure: () -> Void) + func perform(closure: @escaping () -> Void) { if self.isAsync { - Async.main(after: 0.01, block: closure) + Async.main(after: 0.01, closure) } else { closure() From 422e1131c8787fb821ef8998242c0e2417b50557 Mon Sep 17 00:00:00 2001 From: r-plus Date: Mon, 17 Oct 2016 20:30:57 +0900 Subject: [PATCH 19/24] Port conditional retry feature from swift/2.2 branch. --- SwiftTask/SwiftTask.swift | 22 ++++++++++++++---- SwiftTaskTests/SwiftTaskTests.swift | 35 +++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index cb4d163..3eb26a7 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -186,6 +186,14 @@ open class Task: Cancellable, CustomStringConvertible self.name = "RejectedTask" } + private convenience init(_errorInfo: ErrorInfo) + { + self.init(_initClosure: { _, progress, fulfill, _reject, configure in + _reject(_errorInfo) + }) + self.name = "RejectedTask" + } + /// /// Create promise-like task which only allows fulfill & reject (no progress & configure) /// @@ -312,16 +320,22 @@ open class Task: Cancellable, CustomStringConvertible } /// Returns new task that is retryable for `maxRetryCount (= maxTryCount-1)` times. - public func retry(_ maxRetryCount: Int) -> Task + /// - Parameter condition: Predicate that will be evaluated on each retry timing. + public func retry(_ maxRetryCount: Int, condition: @escaping ((ErrorInfo) -> Bool) = { _ in true }) -> Task { - if maxRetryCount < 1 { return self } + guard maxRetryCount > 0 else { return self } return Task { machine, progress, fulfill, _reject, configure in let task = self.progress { _, progressValue in progress(progressValue) - }.failure { [unowned self] _ -> Task in - return self.clone().retry(maxRetryCount-1) // clone & try recursively + }.failure { [unowned self] errorInfo -> Task in + if condition(errorInfo) { + return self.clone().retry(maxRetryCount-1, condition: condition) // clone & try recursively + } + else { + return Task(_errorInfo: errorInfo) + } } task.progress { _, progressValue in diff --git a/SwiftTaskTests/SwiftTaskTests.swift b/SwiftTaskTests/SwiftTaskTests.swift index c412ce6..50b689e 100644 --- a/SwiftTaskTests/SwiftTaskTests.swift +++ b/SwiftTaskTests/SwiftTaskTests.swift @@ -892,6 +892,41 @@ class SwiftTaskTests: _TestCase XCTAssertEqual(actualTryCount, maxTryCount, "`actualTryCount` should reach `maxTryCount` because task keeps rejected and never fulfilled.") } + func testRetry_condition() + { + // NOTE: this is async test + if !self.isAsync { return } + + let expect = self.expectation(description: #function) + let maxTryCount = 4 + var actualTryCount = 0 + + Task { progress, fulfill, reject, configure in + + self.perform { + actualTryCount += 1 + reject("ERROR \(actualTryCount)") + } + + }.retry(maxTryCount-1) { error, isCancelled -> Bool in + XCTAssertNotEqual(error!, "ERROR 0", "Should not evaluate retry condition on first try. It is not retry.") + return actualTryCount < 3 + }.failure { error, isCancelled -> String in + + XCTAssertEqual(error!, "ERROR 3") + XCTAssertFalse(isCancelled) + + expect.fulfill() + + return "DUMMY" + + } + + self.wait() + + XCTAssertEqual(actualTryCount, 3) + } + func testRetry_progress() { // NOTE: this is async test From 964206f9c03e14e7c66edabb71bd1b217b49df67 Mon Sep 17 00:00:00 2001 From: Yuichi Hirano Date: Fri, 6 Jan 2017 12:51:01 +0900 Subject: [PATCH 20/24] Add the @discardableResult attribute to some functions. --- SwiftTask/SwiftTask.swift | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index cb4d163..c18d5b0 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -362,7 +362,7 @@ open class Task: Cancellable, CustomStringConvertible return self.progress(&dummyCanceller, progressClosure) } - public func progress(_ canceller: inout C?, _ progressClosure: @escaping (ProgressTuple) -> Void) -> Self + @discardableResult public func progress(_ canceller: inout C?, _ progressClosure: @escaping (ProgressTuple) -> Void) -> Self { var token: _HandlerToken? = nil self._machine.addProgressTupleHandler(&token, progressClosure) @@ -388,7 +388,7 @@ open class Task: Cancellable, CustomStringConvertible return self.then(&dummyCanceller, thenClosure) } - public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task + @discardableResult public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Value2) -> Task { return self.then(&canceller) { (value, errorInfo) -> Task in return Task(value: thenClosure(value, errorInfo)) @@ -403,7 +403,7 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func then(_ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task + @discardableResult public func then(_ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.then(&dummyCanceller, thenClosure) @@ -417,7 +417,7 @@ open class Task: Cancellable, CustomStringConvertible // /// - Returns: New `Task` /// - public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task + @discardableResult public func then(_ canceller: inout C?, _ thenClosure: @escaping (Value?, ErrorInfo?) -> Task) -> Task { return Task { [unowned self, weak canceller] newMachine, progress, fulfill, _reject, configure in @@ -468,7 +468,7 @@ open class Task: Cancellable, CustomStringConvertible return self.success(&dummyCanceller, successClosure) } - public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Value2) -> Task + @discardableResult public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Value2) -> Task { return self.success(&canceller) { (value: Value) -> Task in return Task(value: successClosure(value)) @@ -483,13 +483,13 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func success(_ successClosure: @escaping (Value) -> Task) -> Task + @discardableResult public func success(_ successClosure: @escaping (Value) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.success(&dummyCanceller, successClosure) } - public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Task) -> Task + @discardableResult public func success(_ canceller: inout C?, _ successClosure: @escaping (Value) -> Task) -> Task { var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in @@ -525,7 +525,7 @@ open class Task: Cancellable, CustomStringConvertible return self.failure(&dummyCanceller, failureClosure) } - public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Value) -> Task + @discardableResult public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Value) -> Task { return self.failure(&canceller) { (errorInfo: ErrorInfo) -> Task in return Task(value: failureClosure(errorInfo)) @@ -541,13 +541,13 @@ open class Task: Cancellable, CustomStringConvertible /// /// - Returns: New `Task` /// - public func failure(_ failureClosure: @escaping (ErrorInfo) -> Task) -> Task + @discardableResult public func failure(_ failureClosure: @escaping (ErrorInfo) -> Task) -> Task { var dummyCanceller: Canceller? = nil return self.failure(&dummyCanceller, failureClosure) } - public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Task) -> Task + @discardableResult public func failure(_ canceller: inout C?, _ failureClosure: @escaping (ErrorInfo) -> Task) -> Task { var localCanceller = canceller; defer { canceller = localCanceller } return Task { [unowned self] newMachine, progress, fulfill, _reject, configure in From 38e181c4d147a20345d2faac41c635e81a23e621 Mon Sep 17 00:00:00 2001 From: Koji Murata Date: Tue, 3 Oct 2017 13:05:50 +0900 Subject: [PATCH 21/24] avoid segmentation fault --- SwiftTask/SwiftTask.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/SwiftTask/SwiftTask.swift b/SwiftTask/SwiftTask.swift index cb4d163..1b987ca 100644 --- a/SwiftTask/SwiftTask.swift +++ b/SwiftTask/SwiftTask.swift @@ -366,9 +366,10 @@ open class Task: Cancellable, CustomStringConvertible { var token: _HandlerToken? = nil self._machine.addProgressTupleHandler(&token, progressClosure) + weak var machine = _machine - canceller = C { [weak self] in - self?._machine.removeProgressTupleHandler(token) + canceller = C { + machine?.removeProgressTupleHandler(token) } return self From 4c6aa002ea237b25f5fbec674ed6fb54e952d1c8 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Wed, 4 Oct 2017 20:18:14 +0900 Subject: [PATCH 22/24] Fix xcodeproj (removing Alamofire) --- SwiftTask.xcodeproj/project.pbxproj | 4 ---- 1 file changed, 4 deletions(-) diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index 85dfdaa..35ec5a4 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -20,8 +20,6 @@ 1F6A8CA319A4E4F200369A5D /* SwiftTaskTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1F46DEE3199EDF1000F97868 /* SwiftTaskTests.swift */; }; 1FB3B8F31B0A194F00F78900 /* _Atomic.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FB3B8F21B0A194F00F78900 /* _Atomic.swift */; }; 1FB3B8F71C5CF2CA00C1A479 /* SwiftTask.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1F46DED4199EDF1000F97868 /* SwiftTask.framework */; }; - 1FCF71121AD8CD2B007079C2 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FCF71111AD8CD2B007079C2 /* Alamofire.framework */; }; - 1FCF71161AD8CD38007079C2 /* Alamofire.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1FCF71151AD8CD38007079C2 /* Alamofire.framework */; }; 1FD7197B1AFE387C00BC38C4 /* Cancellable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FD7197A1AFE387C00BC38C4 /* Cancellable.swift */; }; 1FF52EB41A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF52EB31A4C395A00B4BA28 /* _InterruptableTask.swift */; }; 1FF52EB51A4C395A00B4BA28 /* _InterruptableTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1FF52EB31A4C395A00B4BA28 /* _InterruptableTask.swift */; }; @@ -104,7 +102,6 @@ files = ( 48A1E8221A366F9C007619EB /* SwiftTask.framework in Frameworks */, 1F4C7AD71B7CD27200DEB1AE /* Async.framework in Frameworks */, - 1FCF71161AD8CD38007079C2 /* Alamofire.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -114,7 +111,6 @@ files = ( 1FB3B8F71C5CF2CA00C1A479 /* SwiftTask.framework in Frameworks */, 1F4C7AD91B7CD27600DEB1AE /* Async.framework in Frameworks */, - 1FCF71121AD8CD2B007079C2 /* Alamofire.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; From 5c335e1d676f95a69aaf6683e9d57b6e0d9b08c5 Mon Sep 17 00:00:00 2001 From: Yasuhiro Inami Date: Wed, 4 Oct 2017 20:27:40 +0900 Subject: [PATCH 23/24] [Test] Set MACOSX_DEPLOYMENT_TARGET = 10.10 for test targets --- SwiftTask.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index 35ec5a4..1b3c4b7 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -554,6 +554,7 @@ "$(inherited)", ); INFOPLIST_FILE = SwiftTaskTests/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -566,6 +567,7 @@ buildSettings = { COMBINE_HIDPI_IMAGES = YES; INFOPLIST_FILE = SwiftTaskTests/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; @@ -581,6 +583,7 @@ "$(inherited)", ); INFOPLIST_FILE = SwiftTaskTests/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; @@ -592,6 +595,7 @@ baseConfigurationReference = 1FFADCDE1C5CEC1B000B66BE /* UniversalFramework_Test.xcconfig */; buildSettings = { INFOPLIST_FILE = SwiftTaskTests/Info.plist; + MACOSX_DEPLOYMENT_TARGET = 10.10; PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; From 21753f10e5a8a1348e6249b8022e39f6ddfd4d57 Mon Sep 17 00:00:00 2001 From: Masayuki Uehara Date: Thu, 26 Oct 2017 12:34:49 +0900 Subject: [PATCH 24/24] Enabled to work with swift 4 --- SwiftTask.xcodeproj/project.pbxproj | 24 ++++++++++++++++++- .../xcshareddata/xcschemes/SwiftTask.xcscheme | 4 +++- SwiftTask/_StateMachine.swift | 2 +- SwiftTaskTests/SwiftTaskTests.swift | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/SwiftTask.xcodeproj/project.pbxproj b/SwiftTask.xcodeproj/project.pbxproj index 1b3c4b7..ac6b1ab 100644 --- a/SwiftTask.xcodeproj/project.pbxproj +++ b/SwiftTask.xcodeproj/project.pbxproj @@ -303,7 +303,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0800; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Yasuhiro Inami"; TargetAttributes = { 1F46DED3199EDF1000F97868 = { @@ -433,13 +433,21 @@ 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; COPY_PHASE_STRIP = NO; @@ -478,13 +486,21 @@ 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; COPY_PHASE_STRIP = YES; @@ -522,6 +538,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -541,6 +558,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(PROJECT_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -558,6 +576,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -571,6 +590,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -587,6 +607,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -599,6 +620,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "com.inamiy.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SWIFT_VERSION = 4.0; VALIDATE_PRODUCT = YES; }; name = Release; diff --git a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme index 09eb84c..234c8fd 100644 --- a/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme +++ b/SwiftTask.xcodeproj/xcshareddata/xcschemes/SwiftTask.xcscheme @@ -1,6 +1,6 @@ } for handler in self._progressTupleHandlers { - handler(oldProgress: oldProgress, newProgress: progress) + handler((oldProgress: oldProgress, newProgress: progress)) } } } diff --git a/SwiftTaskTests/SwiftTaskTests.swift b/SwiftTaskTests/SwiftTaskTests.swift index 50b689e..60d9342 100644 --- a/SwiftTaskTests/SwiftTaskTests.swift +++ b/SwiftTaskTests/SwiftTaskTests.swift @@ -536,7 +536,7 @@ class SwiftTaskTests: _TestCase let task = _interruptableTask(progressCount: 5) // 1st async task (5 progresses) // chain async-task with then - let task3 = task.then { _ -> _InterruptableTask in + let task3 = task.then { _,_ -> _InterruptableTask in let task2 = _interruptableTask(progressCount: 7) // 2st async task (7 progresses) return task2 } @@ -760,7 +760,7 @@ class SwiftTaskTests: _TestCase weak var innerTask: _InterruptableTask? // chain async-task with `then` - let task2 = task.then { _ -> _InterruptableTask in + let task2 = task.then { _,_ -> _InterruptableTask in innerTask = _interruptableTask(progressCount: 5) return innerTask! }