From c705e984eab62d9e25ca25098d5dee375b4efd19 Mon Sep 17 00:00:00 2001 From: Tom Kroening Date: Wed, 12 Apr 2017 22:13:03 -0500 Subject: [PATCH] Converted project to Swift 3.0. All unit tests passing. Closes #5 --- AsyncTask.xcodeproj/project.pbxproj | 257 ++---------------- .../xcschemes/AsyncTaskDemo.xcscheme | 91 ------- .../xcschemes/AsyncTaskOSX.xcscheme | 2 +- .../xcschemes/AsyncTaskOSXTests.xcscheme | 2 +- .../xcschemes/AsyncTaskTVOS.xcscheme | 2 +- .../xcschemes/AsyncTaskWatchOS.xcscheme | 2 +- .../xcschemes/AsyncTaskiOS.xcscheme | 2 +- Cartfile.private | 4 +- Cartfile.resolved | 6 +- Demo/AppDelegate.swift | 51 ---- .../AppIcon.appiconset/Contents.json | 38 --- Demo/Base.lproj/LaunchScreen.storyboard | 27 -- Demo/Info.plist | 38 --- Source/Base/Collection.swift | 66 ++--- Source/Base/Config.swift | 8 +- Source/Base/DispatchQueue.swift | 46 ++-- Source/Base/Helper.swift | 12 +- Source/Base/Task.swift | 26 +- Source/Base/ThrowableTask.swift | 62 ++--- Source/Base/Thunkify.swift | 10 +- Tests/DispatchQueue.swift | 18 +- Tests/Helper.swift | 44 +-- Tests/Task.swift | 24 +- Tests/ThrowableTask.swift | 8 +- Tests/TrivialExample.swift | 22 +- 25 files changed, 215 insertions(+), 653 deletions(-) delete mode 100644 AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskDemo.xcscheme delete mode 100755 Demo/AppDelegate.swift delete mode 100644 Demo/Assets.xcassets/AppIcon.appiconset/Contents.json delete mode 100644 Demo/Base.lproj/LaunchScreen.storyboard delete mode 100644 Demo/Info.plist diff --git a/AsyncTask.xcodeproj/project.pbxproj b/AsyncTask.xcodeproj/project.pbxproj index ebacd90..aac5fa1 100644 --- a/AsyncTask.xcodeproj/project.pbxproj +++ b/AsyncTask.xcodeproj/project.pbxproj @@ -18,32 +18,6 @@ 094250641D18D4E300A8EC2C /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942505E1D18D4E300A8EC2C /* Task.swift */; }; 094250651D18D4E300A8EC2C /* ThrowableTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942505F1D18D4E300A8EC2C /* ThrowableTask.swift */; }; 094250661D18D4E300A8EC2C /* TrivialExample.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250601D18D4E300A8EC2C /* TrivialExample.swift */; }; - 094250671D18D9CD00A8EC2C /* AsyncTask.h in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1E51D18B86C00B0ABA7 /* AsyncTask.h */; }; - 094250681D18D9CD00A8EC2C /* Info.plist in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1E61D18B86C00B0ABA7 /* Info.plist */; }; - 094250691D18D9D700A8EC2C /* AsyncTask.h in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1CF1D18B7F400B0ABA7 /* AsyncTask.h */; }; - 0942506A1D18D9D700A8EC2C /* Info.plist in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1D11D18B7F400B0ABA7 /* Info.plist */; }; - 0942506B1D18D9DD00A8EC2C /* AsyncTaskTVOS.h in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1DC1D18B81A00B0ABA7 /* AsyncTaskTVOS.h */; }; - 0942506C1D18D9DD00A8EC2C /* Info.plist in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1DE1D18B81A00B0ABA7 /* Info.plist */; }; - 0942506D1D18D9E600A8EC2C /* AsyncTaskWatchOS.h in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1F01D18B88900B0ABA7 /* AsyncTaskWatchOS.h */; }; - 0942506E1D18D9E600A8EC2C /* Info.plist in Sources */ = {isa = PBXBuildFile; fileRef = 097BB1F21D18B88900B0ABA7 /* Info.plist */; }; - 094250771D1918A700A8EC2C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250761D1918A700A8EC2C /* AppDelegate.swift */; }; - 0942507E1D1918A700A8EC2C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0942507D1D1918A700A8EC2C /* Assets.xcassets */; }; - 094250811D1918A700A8EC2C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0942507F1D1918A700A8EC2C /* LaunchScreen.storyboard */; }; - 094250931D19198400A8EC2C /* ChainedAnimationDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250871D19198400A8EC2C /* ChainedAnimationDemoViewController.swift */; }; - 094250941D19198400A8EC2C /* ImageDownloadDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250881D19198400A8EC2C /* ImageDownloadDemoViewController.swift */; }; - 094250951D19198400A8EC2C /* ImagePickerTask.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250891D19198400A8EC2C /* ImagePickerTask.swift */; }; - 094250961D19198400A8EC2C /* ImagePickerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508A1D19198400A8EC2C /* ImagePickerViewController.swift */; }; - 094250971D19198400A8EC2C /* LogsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508B1D19198400A8EC2C /* LogsTableViewController.swift */; }; - 094250981D19198400A8EC2C /* MenuTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508C1D19198400A8EC2C /* MenuTableViewController.swift */; }; - 094250991D19198400A8EC2C /* Misc.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508D1D19198400A8EC2C /* Misc.swift */; }; - 0942509A1D19198400A8EC2C /* NSURL+Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508E1D19198400A8EC2C /* NSURL+Task.swift */; }; - 0942509B1D19198400A8EC2C /* Request.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0942508F1D19198400A8EC2C /* Request.swift */; }; - 0942509C1D19198400A8EC2C /* RequestDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250901D19198400A8EC2C /* RequestDemoViewController.swift */; }; - 0942509D1D19198400A8EC2C /* RequestTasks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250911D19198400A8EC2C /* RequestTasks.swift */; }; - 0942509E1D19198400A8EC2C /* SleepDemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 094250921D19198400A8EC2C /* SleepDemoViewController.swift */; }; - 094250A11D191A0200A8EC2C /* AsyncTask.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 097BB1AE1D18B70400B0ABA7 /* AsyncTask.framework */; }; - 094250A41D191B7D00A8EC2C /* Cartography.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 094250A21D191B7D00A8EC2C /* Cartography.framework */; }; - 094250A51D191B7D00A8EC2C /* ReactiveUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 094250A31D191B7D00A8EC2C /* ReactiveUI.framework */; }; 097BB1D01D18B7F400B0ABA7 /* AsyncTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 097BB1CF1D18B7F400B0ABA7 /* AsyncTask.h */; settings = {ATTRIBUTES = (Public, ); }; }; 097BB1DD1D18B81A00B0ABA7 /* AsyncTaskTVOS.h in Headers */ = {isa = PBXBuildFile; fileRef = 097BB1DC1D18B81A00B0ABA7 /* AsyncTaskTVOS.h */; settings = {ATTRIBUTES = (Public, ); }; }; 097BB1E71D18B86C00B0ABA7 /* AsyncTask.h in Headers */ = {isa = PBXBuildFile; fileRef = 097BB1E51D18B86C00B0ABA7 /* AsyncTask.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -109,28 +83,11 @@ 094250411D18D1BB00A8EC2C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Tests/Info.plist; sourceTree = ""; }; 094250491D18D1DD00A8EC2C /* Nimble.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Nimble.framework; path = Carthage/Build/Mac/Nimble.framework; sourceTree = ""; }; 0942504A1D18D1DD00A8EC2C /* Quick.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Quick.framework; path = Carthage/Build/Mac/Quick.framework; sourceTree = ""; }; - 0942505C1D18D4E300A8EC2C /* DispatchQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = DispatchQueue.swift; path = Tests/DispatchQueue.swift; sourceTree = SOURCE_ROOT; }; + 0942505C1D18D4E300A8EC2C /* DispatchQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = DispatchQueue.swift; path = Tests/DispatchQueue.swift; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 0942505D1D18D4E300A8EC2C /* Helper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Helper.swift; path = Tests/Helper.swift; sourceTree = SOURCE_ROOT; }; 0942505E1D18D4E300A8EC2C /* Task.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Task.swift; path = Tests/Task.swift; sourceTree = SOURCE_ROOT; }; - 0942505F1D18D4E300A8EC2C /* ThrowableTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ThrowableTask.swift; path = Tests/ThrowableTask.swift; sourceTree = SOURCE_ROOT; }; - 094250601D18D4E300A8EC2C /* TrivialExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = TrivialExample.swift; path = Tests/TrivialExample.swift; sourceTree = SOURCE_ROOT; }; - 094250741D1918A700A8EC2C /* AsyncTaskDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AsyncTaskDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; - 094250761D1918A700A8EC2C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; - 0942507D1D1918A700A8EC2C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; - 094250801D1918A700A8EC2C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; - 094250821D1918A700A8EC2C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 094250871D19198400A8EC2C /* ChainedAnimationDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ChainedAnimationDemoViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/ChainedAnimationDemoViewController.swift"; sourceTree = ""; }; - 094250881D19198400A8EC2C /* ImageDownloadDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImageDownloadDemoViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/ImageDownloadDemoViewController.swift"; sourceTree = ""; }; - 094250891D19198400A8EC2C /* ImagePickerTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImagePickerTask.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/ImagePickerTask.swift"; sourceTree = ""; }; - 0942508A1D19198400A8EC2C /* ImagePickerViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ImagePickerViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/ImagePickerViewController.swift"; sourceTree = ""; }; - 0942508B1D19198400A8EC2C /* LogsTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = LogsTableViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/LogsTableViewController.swift"; sourceTree = ""; }; - 0942508C1D19198400A8EC2C /* MenuTableViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = MenuTableViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/MenuTableViewController.swift"; sourceTree = ""; }; - 0942508D1D19198400A8EC2C /* Misc.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Misc.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/Misc.swift"; sourceTree = ""; }; - 0942508E1D19198400A8EC2C /* NSURL+Task.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSURL+Task.swift"; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/NSURL+Task.swift"; sourceTree = ""; }; - 0942508F1D19198400A8EC2C /* Request.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Request.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/Request.swift"; sourceTree = ""; }; - 094250901D19198400A8EC2C /* RequestDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RequestDemoViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/RequestDemoViewController.swift"; sourceTree = ""; }; - 094250911D19198400A8EC2C /* RequestTasks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = RequestTasks.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/RequestTasks.swift"; sourceTree = ""; }; - 094250921D19198400A8EC2C /* SleepDemoViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = SleepDemoViewController.swift; path = "../../../../Downloads/AsyncTask-25a1cefcd5d7fdc4957fdef7b8d492753d590e82/Example/AsyncTask/SleepDemoViewController.swift"; sourceTree = ""; }; + 0942505F1D18D4E300A8EC2C /* ThrowableTask.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = ThrowableTask.swift; path = Tests/ThrowableTask.swift; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; + 094250601D18D4E300A8EC2C /* TrivialExample.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; name = TrivialExample.swift; path = Tests/TrivialExample.swift; sourceTree = SOURCE_ROOT; xcLanguageSpecificationIdentifier = xcode.lang.swift; }; 094250A21D191B7D00A8EC2C /* Cartography.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cartography.framework; path = Carthage/Build/iOS/Cartography.framework; sourceTree = ""; }; 094250A31D191B7D00A8EC2C /* ReactiveUI.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveUI.framework; path = Carthage/Build/iOS/ReactiveUI.framework; sourceTree = ""; }; 097BB1AE1D18B70400B0ABA7 /* AsyncTask.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = AsyncTask.framework; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -167,16 +124,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 094250711D1918A700A8EC2C /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - 094250A11D191A0200A8EC2C /* AsyncTask.framework in Frameworks */, - 094250A41D191B7D00A8EC2C /* Cartography.framework in Frameworks */, - 094250A51D191B7D00A8EC2C /* ReactiveUI.framework in Frameworks */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 097BB1AA1D18B70400B0ABA7 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -234,49 +181,9 @@ name = Source; sourceTree = ""; }; - 094250751D1918A700A8EC2C /* Demo */ = { - isa = PBXGroup; - children = ( - 094250761D1918A700A8EC2C /* AppDelegate.swift */, - 0942509F1D1919A200A8EC2C /* Demos */, - 094250A01D1919D700A8EC2C /* Tasks */, - 0942508D1D19198400A8EC2C /* Misc.swift */, - 0942507D1D1918A700A8EC2C /* Assets.xcassets */, - 0942507F1D1918A700A8EC2C /* LaunchScreen.storyboard */, - 094250821D1918A700A8EC2C /* Info.plist */, - ); - path = Demo; - sourceTree = ""; - }; - 0942509F1D1919A200A8EC2C /* Demos */ = { - isa = PBXGroup; - children = ( - 094250871D19198400A8EC2C /* ChainedAnimationDemoViewController.swift */, - 094250881D19198400A8EC2C /* ImageDownloadDemoViewController.swift */, - 0942508A1D19198400A8EC2C /* ImagePickerViewController.swift */, - 0942508C1D19198400A8EC2C /* MenuTableViewController.swift */, - 094250901D19198400A8EC2C /* RequestDemoViewController.swift */, - 094250921D19198400A8EC2C /* SleepDemoViewController.swift */, - 0942508B1D19198400A8EC2C /* LogsTableViewController.swift */, - ); - name = Demos; - sourceTree = ""; - }; - 094250A01D1919D700A8EC2C /* Tasks */ = { - isa = PBXGroup; - children = ( - 094250891D19198400A8EC2C /* ImagePickerTask.swift */, - 0942508E1D19198400A8EC2C /* NSURL+Task.swift */, - 0942508F1D19198400A8EC2C /* Request.swift */, - 094250911D19198400A8EC2C /* RequestTasks.swift */, - ); - name = Tasks; - sourceTree = ""; - }; 097BB1A41D18B70400B0ABA7 = { isa = PBXGroup; children = ( - 094250751D1918A700A8EC2C /* Demo */, 0942506F1D18E67A00A8EC2C /* Source */, 0942503E1D18D1BB00A8EC2C /* Tests */, 097BB1AF1D18B70400B0ABA7 /* Products */, @@ -292,7 +199,6 @@ 097BB1DA1D18B81A00B0ABA7 /* AsyncTask.framework */, 097BB1EE1D18B88900B0ABA7 /* AsyncTask.framework */, 0942503D1D18D1BB00A8EC2C /* AsyncTaskOSXTests.xctest */, - 094250741D1918A700A8EC2C /* AsyncTaskDemo.app */, ); name = Products; sourceTree = ""; @@ -423,24 +329,6 @@ productReference = 0942503D1D18D1BB00A8EC2C /* AsyncTaskOSXTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 094250731D1918A700A8EC2C /* AsyncTaskDemo */ = { - isa = PBXNativeTarget; - buildConfigurationList = 094250831D1918A700A8EC2C /* Build configuration list for PBXNativeTarget "AsyncTaskDemo" */; - buildPhases = ( - 094250701D1918A700A8EC2C /* Sources */, - 094250711D1918A700A8EC2C /* Frameworks */, - 094250721D1918A700A8EC2C /* Resources */, - 094250A61D191BB800A8EC2C /* Run Script */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = AsyncTaskDemo; - productName = AsyncTaskDemo; - productReference = 094250741D1918A700A8EC2C /* AsyncTaskDemo.app */; - productType = "com.apple.product-type.application"; - }; 097BB1AD1D18B70400B0ABA7 /* AsyncTaskiOS */ = { isa = PBXNativeTarget; buildConfigurationList = 097BB1C21D18B70400B0ABA7 /* Build configuration list for PBXNativeTarget "AsyncTaskiOS" */; @@ -520,28 +408,30 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0830; ORGANIZATIONNAME = "Zhixuan Lai"; TargetAttributes = { 0942503C1D18D1BB00A8EC2C = { CreatedOnToolsVersion = 7.3.1; - }; - 094250731D1918A700A8EC2C = { - CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0830; }; 097BB1AD1D18B70400B0ABA7 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 6DSXGUT2JS; + LastSwiftMigration = 0830; }; 097BB1CC1D18B7F400B0ABA7 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0830; }; 097BB1D91D18B81A00B0ABA7 = { CreatedOnToolsVersion = 7.3.1; DevelopmentTeam = 6DSXGUT2JS; + LastSwiftMigration = 0830; }; 097BB1ED1D18B88900B0ABA7 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0830; }; }; }; @@ -558,7 +448,6 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 094250731D1918A700A8EC2C /* AsyncTaskDemo */, 097BB1AD1D18B70400B0ABA7 /* AsyncTaskiOS */, 097BB1CC1D18B7F400B0ABA7 /* AsyncTaskOSX */, 097BB1D91D18B81A00B0ABA7 /* AsyncTaskTVOS */, @@ -576,15 +465,6 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 094250721D1918A700A8EC2C /* Resources */ = { - isa = PBXResourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 094250811D1918A700A8EC2C /* LaunchScreen.storyboard in Resources */, - 0942507E1D1918A700A8EC2C /* Assets.xcassets in Resources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 097BB1AC1D18B70400B0ABA7 /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -615,25 +495,6 @@ }; /* End PBXResourcesBuildPhase section */ -/* Begin PBXShellScriptBuildPhase section */ - 094250A61D191BB800A8EC2C /* Run Script */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - "$(SRCROOT)/Carthage/Build/iOS/ReactiveUI.framework", - "$(SRCROOT)/Carthage/Build/iOS/Cartography.framework", - ); - name = "Run Script"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "/usr/local/bin/carthage copy-frameworks"; - }; -/* End PBXShellScriptBuildPhase section */ - /* Begin PBXSourcesBuildPhase section */ 094250391D18D1BB00A8EC2C /* Sources */ = { isa = PBXSourcesBuildPhase; @@ -647,32 +508,10 @@ ); runOnlyForDeploymentPostprocessing = 0; }; - 094250701D1918A700A8EC2C /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 094250971D19198400A8EC2C /* LogsTableViewController.swift in Sources */, - 094250961D19198400A8EC2C /* ImagePickerViewController.swift in Sources */, - 0942509A1D19198400A8EC2C /* NSURL+Task.swift in Sources */, - 0942509B1D19198400A8EC2C /* Request.swift in Sources */, - 0942509D1D19198400A8EC2C /* RequestTasks.swift in Sources */, - 094250991D19198400A8EC2C /* Misc.swift in Sources */, - 094250771D1918A700A8EC2C /* AppDelegate.swift in Sources */, - 0942509C1D19198400A8EC2C /* RequestDemoViewController.swift in Sources */, - 0942509E1D19198400A8EC2C /* SleepDemoViewController.swift in Sources */, - 094250981D19198400A8EC2C /* MenuTableViewController.swift in Sources */, - 094250931D19198400A8EC2C /* ChainedAnimationDemoViewController.swift in Sources */, - 094250941D19198400A8EC2C /* ImageDownloadDemoViewController.swift in Sources */, - 094250951D19198400A8EC2C /* ImagePickerTask.swift in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; 097BB1A91D18B70400B0ABA7 /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 094250671D18D9CD00A8EC2C /* AsyncTask.h in Sources */, - 094250681D18D9CD00A8EC2C /* Info.plist in Sources */, 097BB1FE1D18B8BA00B0ABA7 /* Collection.swift in Sources */, 097BB2031D18B8BA00B0ABA7 /* Config.swift in Sources */, 097BB2121D18B8BA00B0ABA7 /* Task.swift in Sources */, @@ -687,8 +526,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 094250691D18D9D700A8EC2C /* AsyncTask.h in Sources */, - 0942506A1D18D9D700A8EC2C /* Info.plist in Sources */, 097BB2001D18B8BA00B0ABA7 /* Collection.swift in Sources */, 097BB2051D18B8BA00B0ABA7 /* Config.swift in Sources */, 097BB2141D18B8BA00B0ABA7 /* Task.swift in Sources */, @@ -703,8 +540,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 0942506B1D18D9DD00A8EC2C /* AsyncTaskTVOS.h in Sources */, - 0942506C1D18D9DD00A8EC2C /* Info.plist in Sources */, 097BB2011D18B8BA00B0ABA7 /* Collection.swift in Sources */, 097BB2061D18B8BA00B0ABA7 /* Config.swift in Sources */, 097BB2151D18B8BA00B0ABA7 /* Task.swift in Sources */, @@ -719,8 +554,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 0942506D1D18D9E600A8EC2C /* AsyncTaskWatchOS.h in Sources */, - 0942506E1D18D9E600A8EC2C /* Info.plist in Sources */, 097BB2021D18B8BA00B0ABA7 /* Collection.swift in Sources */, 097BB2071D18B8BA00B0ABA7 /* Config.swift in Sources */, 097BB2161D18B8BA00B0ABA7 /* Task.swift in Sources */, @@ -741,17 +574,6 @@ }; /* End PBXTargetDependency section */ -/* Begin PBXVariantGroup section */ - 0942507F1D1918A700A8EC2C /* LaunchScreen.storyboard */ = { - isa = PBXVariantGroup; - children = ( - 094250801D1918A700A8EC2C /* Base */, - ); - name = LaunchScreen.storyboard; - sourceTree = ""; - }; -/* End PBXVariantGroup section */ - /* Begin XCBuildConfiguration section */ 094250461D18D1BB00A8EC2C /* Debug */ = { isa = XCBuildConfiguration; @@ -770,6 +592,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -789,38 +612,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.axcel.AsyncTaskOSXTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = macosx; - }; - name = Release; - }; - 094250841D1918A700A8EC2C /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/Demo/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.axcel.AsyncTaskDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 094250851D1918A700A8EC2C /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; - FRAMEWORK_SEARCH_PATHS = ( - "$(inherited)", - "$(PROJECT_DIR)/Carthage/Build/iOS", - ); - INFOPLIST_FILE = "$(SRCROOT)/Demo/Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 9.3; - LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = com.axcel.AsyncTaskDemo; - PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -838,8 +630,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = ""; @@ -889,8 +683,10 @@ 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_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; CODE_SIGN_IDENTITY = ""; @@ -913,6 +709,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.10; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -924,7 +721,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -937,6 +734,7 @@ PRODUCT_NAME = AsyncTask; PROVISIONING_PROFILE = ""; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -944,7 +742,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; - "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -958,6 +756,7 @@ PRODUCT_NAME = AsyncTask; PROVISIONING_PROFILE = ""; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -980,6 +779,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -1002,6 +802,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -1009,6 +810,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -1020,6 +822,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -1029,6 +832,7 @@ isa = XCBuildConfiguration; buildSettings = { CODE_SIGN_IDENTITY = "iPhone Developer"; + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -1040,6 +844,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -1060,6 +865,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.2; }; @@ -1080,6 +886,7 @@ PRODUCT_NAME = AsyncTask; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.2; }; @@ -1097,14 +904,6 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 094250831D1918A700A8EC2C /* Build configuration list for PBXNativeTarget "AsyncTaskDemo" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 094250841D1918A700A8EC2C /* Debug */, - 094250851D1918A700A8EC2C /* Release */, - ); - defaultConfigurationIsVisible = 0; - }; 097BB1A81D18B70400B0ABA7 /* Build configuration list for PBXProject "AsyncTask" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskDemo.xcscheme b/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskDemo.xcscheme deleted file mode 100644 index df7a3a2..0000000 --- a/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskDemo.xcscheme +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskOSX.xcscheme b/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskOSX.xcscheme index 40fd80d..556e9a5 100644 --- a/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskOSX.xcscheme +++ b/AsyncTask.xcodeproj/xcshareddata/xcschemes/AsyncTaskOSX.xcscheme @@ -1,6 +1,6 @@ 0.9.2 -github "Quick/Nimble" ~> 4.0 +github "Quick/Quick" +github "Quick/Nimble" github "zhxnlai/ReactiveUI" github "robb/Cartography" diff --git a/Cartfile.resolved b/Cartfile.resolved index c6d09d2..82ff7c9 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,4 +1,4 @@ -github "robb/Cartography" "0.6.0" -github "Quick/Nimble" "v4.1.0" -github "Quick/Quick" "v0.9.2" +github "Quick/Nimble" "v6.1.0" +github "Quick/Quick" "v1.1.0" +github "robb/Cartography" "1.1.0" github "zhxnlai/ReactiveUI" "0.0.3" diff --git a/Demo/AppDelegate.swift b/Demo/AppDelegate.swift deleted file mode 100755 index 7a13853..0000000 --- a/Demo/AppDelegate.swift +++ /dev/null @@ -1,51 +0,0 @@ -// -// AppDelegate.swift -// AsyncTask -// -// Created by Zhixuan Lai on 05/27/2016. -// Copyright (c) 2016 Zhixuan Lai. All rights reserved. -// - -import UIKit - -@UIApplicationMain -class AppDelegate: UIResponder, UIApplicationDelegate { - - var window: UIWindow? - - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - window = UIWindow(frame: UIScreen.mainScreen().bounds) - if let window = window { - let menuViewController = MenuTableViewController(style: .Grouped) - window.rootViewController = UINavigationController(rootViewController: menuViewController) - window.makeKeyAndVisible() - } - return true - } - - func applicationWillResignActive(application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - - -} - diff --git a/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json b/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json deleted file mode 100644 index 118c98f..0000000 --- a/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "images" : [ - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "29x29", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "40x40", - "scale" : "3x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "2x" - }, - { - "idiom" : "iphone", - "size" : "60x60", - "scale" : "3x" - } - ], - "info" : { - "version" : 1, - "author" : "xcode" - } -} \ No newline at end of file diff --git a/Demo/Base.lproj/LaunchScreen.storyboard b/Demo/Base.lproj/LaunchScreen.storyboard deleted file mode 100644 index 2e721e1..0000000 --- a/Demo/Base.lproj/LaunchScreen.storyboard +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/Demo/Info.plist b/Demo/Info.plist deleted file mode 100644 index d39a4da..0000000 --- a/Demo/Info.plist +++ /dev/null @@ -1,38 +0,0 @@ - - - - - CFBundleDevelopmentRegion - en - CFBundleExecutable - $(EXECUTABLE_NAME) - CFBundleIdentifier - $(PRODUCT_BUNDLE_IDENTIFIER) - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - $(PRODUCT_NAME) - CFBundlePackageType - APPL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - LSRequiresIPhoneOS - - UILaunchStoryboardName - LaunchScreen - UIRequiredDeviceCapabilities - - armv7 - - UISupportedInterfaceOrientations - - UIInterfaceOrientationPortrait - UIInterfaceOrientationLandscapeLeft - UIInterfaceOrientationLandscapeRight - - - diff --git a/Source/Base/Collection.swift b/Source/Base/Collection.swift index f7fdc3e..1fa5042 100644 --- a/Source/Base/Collection.swift +++ b/Source/Base/Collection.swift @@ -3,32 +3,34 @@ // Pods // // Created by Zhixuan Lai on 5/27/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation -extension SequenceType where Generator.Element : ThrowableTaskType { +extension Sequence where Iterator.Element : ThrowableTaskType { - public func awaitFirstResult(queue: DispatchQueue = DefaultQueue) -> Result { + public func awaitFirstResult(_ queue: AsyncQueue = DefaultQueue) -> Result { let tasks = map{$0} - return Task {(callback: Result -> ()) in + return Task { + (callback: @escaping (Result) -> ()) + in tasks.concurrentForEach(queue, transform: {task in task.awaitResult()}) { index, result in callback(result) } }.await(queue) } - public func awaitAllResults(queue: DispatchQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Result] { + public func awaitAllResults(_ queue: AsyncQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Result] { let tasks = map{$0} return tasks.concurrentMap(queue, concurrency: concurrency) {task in task.awaitResult()} } - public func awaitFirst(queue: DispatchQueue = DefaultQueue) throws -> Generator.Element.ReturnType { + public func awaitFirst(_ queue: AsyncQueue = DefaultQueue) throws -> Iterator.Element.ReturnType { return try awaitFirstResult(queue).extract() } - public func awaitAll(queue: DispatchQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) throws -> [Generator.Element.ReturnType] { + public func awaitAll(_ queue: AsyncQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) throws -> [Iterator.Element.ReturnType] { return try awaitAllResults(queue, concurrency: concurrency).map {try $0.extract()} } @@ -36,28 +38,28 @@ extension SequenceType where Generator.Element : ThrowableTaskType { extension Dictionary where Value : ThrowableTaskType { - public func awaitFirst(queue: DispatchQueue = DefaultQueue) throws -> Value.ReturnType { + public func awaitFirst(_ queue: AsyncQueue = DefaultQueue) throws -> Value.ReturnType { return try values.awaitFirst(queue) } - public func awaitAll(queue: DispatchQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) throws -> [Key: Value.ReturnType] { + public func awaitAll(_ queue: AsyncQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) throws -> [Key: Value.ReturnType] { let elements = Array(zip(Array(keys), try values.awaitAll(queue, concurrency: concurrency))) return Dictionary(elements: elements) } } -extension SequenceType where Generator.Element : TaskType { +extension Sequence where Iterator.Element : TaskType { - var throwableTasks: [ThrowableTask] { + var throwableTasks: [ThrowableTask] { return map {$0.throwableTask} } - public func awaitFirst(queue: DispatchQueue = DefaultQueue) -> Generator.Element.ReturnType { + public func awaitFirst(_ queue: AsyncQueue = DefaultQueue) -> Iterator.Element.ReturnType { return try! throwableTasks.awaitFirstResult(queue).extract() } - public func awaitAll(queue: DispatchQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Generator.Element.ReturnType] { + public func awaitAll(_ queue: AsyncQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Iterator.Element.ReturnType] { return throwableTasks.awaitAllResults(queue, concurrency: concurrency).map {result in try! result.extract() } } @@ -69,11 +71,11 @@ extension Dictionary where Value : TaskType { return values.throwableTasks } - public func awaitFirst(queue: DispatchQueue = DefaultQueue) -> Value.ReturnType { + public func awaitFirst(_ queue: AsyncQueue = DefaultQueue) -> Value.ReturnType { return try! throwableTasks.awaitFirstResult(queue).extract() } - public func await(queue: DispatchQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Key: Value.ReturnType] { + public func await(_ queue: AsyncQueue = DefaultQueue, concurrency: Int = DefaultConcurrency) -> [Key: Value.ReturnType] { let elements = Array(zip(Array(keys), try! throwableTasks.awaitAll(queue, concurrency: concurrency))) return Dictionary(elements: elements) } @@ -93,50 +95,50 @@ extension Dictionary { extension Array { - func concurrentForEach(queue: DispatchQueue, transform: Element -> U, completion: (Int, U) -> ()) { - let fd_sema = dispatch_semaphore_create(0) + func concurrentForEach(_ queue: AsyncQueue, transform: @escaping (Element) -> U, completion: @escaping (Int, U) -> ()) { + let fd_sema = DispatchSemaphore(value: 0) var numberOfCompletedTasks = 0 let numberOfTasks = count - for (index, item) in enumerate() { - dispatch_async(queue.get()) { + for (index, item) in enumerated() { + queue.get().async { let result = transform(item) - dispatch_sync(DispatchQueue.getCollectionQueue().get()) { + AsyncQueue.getCollectionQueue().get().sync { completion(index, result) numberOfCompletedTasks += 1 if numberOfCompletedTasks == numberOfTasks { - dispatch_semaphore_signal(fd_sema) + fd_sema.signal() } } } } - dispatch_semaphore_wait(fd_sema, dispatch_time_t(timeInterval: -1)) + _ = fd_sema.wait(timeout: DispatchTime(timeInterval: -1)) } - func concurrentMap(queue: DispatchQueue, concurrency: Int, transform: Element -> U) -> [U] { - let fd_sema = dispatch_semaphore_create(0) - let fd_sema2 = dispatch_semaphore_create(concurrency) + func concurrentMap(_ queue: AsyncQueue, concurrency: Int, transform: @escaping (Element) -> U) -> [U] { + let fd_sema = DispatchSemaphore(value: 0) + let fd_sema2 = DispatchSemaphore(value: concurrency) - var results = [U?](count: count, repeatedValue: nil) + var results = [U?](repeating: nil, count: count) var numberOfCompletedTasks = 0 let numberOfTasks = count - dispatch_apply(count, queue.get()) {index in - dispatch_semaphore_wait(fd_sema2, dispatch_time_t(timeInterval: -1)) + DispatchQueue.concurrentPerform(iterations: count) {index in + _ = fd_sema2.wait(timeout: DispatchTime(timeInterval: -1)) let result = transform(self[index]) - dispatch_sync(DispatchQueue.getCollectionQueue().get()) { + AsyncQueue.getCollectionQueue().get().sync { results[index] = result numberOfCompletedTasks += 1 if numberOfCompletedTasks == numberOfTasks { - dispatch_semaphore_signal(fd_sema) + fd_sema.signal() } - dispatch_semaphore_signal(fd_sema2) + fd_sema2.signal() } } - dispatch_semaphore_wait(fd_sema, dispatch_time_t(timeInterval: -1)) + _ = fd_sema.wait(timeout: DispatchTime(timeInterval: -1)) return results.flatMap {$0} } diff --git a/Source/Base/Config.swift b/Source/Base/Config.swift index 9f2ee06..fcc3b6e 100644 --- a/Source/Base/Config.swift +++ b/Source/Base/Config.swift @@ -3,13 +3,13 @@ // Pods // // Created by Zhixuan Lai on 5/29/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation -let DefaultQueue = DispatchQueue.UserInitiated +let DefaultQueue = AsyncQueue.userInitiated -let TimeoutForever = NSTimeInterval(-1) +let TimeoutForever = TimeInterval(-1) -let DefaultConcurrency = Int.max \ No newline at end of file +let DefaultConcurrency = Int.max diff --git a/Source/Base/DispatchQueue.swift b/Source/Base/DispatchQueue.swift index a69b163..985cb73 100644 --- a/Source/Base/DispatchQueue.swift +++ b/Source/Base/DispatchQueue.swift @@ -4,42 +4,42 @@ // // Created by Zhixuan Lai on 2/26/16. // Copyright © 2016 Zhixuan Lai. All rights reserved. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 import Foundation // https://developer.apple.com/library/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/PrioritizeWorkWithQoS.html#//apple_ref/doc/uid/TP40015243-CH39-SW39 @available(iOS 8.0, OSX 10.10, *) -public enum DispatchQueue { +public enum AsyncQueue { - case Main - case UserInteractive // Work is virtually instantaneous. - case UserInitiated // Work is nearly instantaneous, such as a few seconds or less. - case Utility // Work takes a few seconds to a few minutes. - case Background // Work takes significant time, such as minutes or hours. - case Custom(dispatch_queue_t) + case main + case userInteractive // Work is virtually instantaneous. + case userInitiated // Work is nearly instantaneous, such as a few seconds or less. + case utility // Work takes a few seconds to a few minutes. + case background // Work takes significant time, such as minutes or hours. + case custom(Dispatch.DispatchQueue) - public func get() -> dispatch_queue_t { + public func get() -> DispatchQueue { switch self { - case .Main: - return dispatch_get_main_queue() - case .UserInteractive: - return dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0) - case .UserInitiated: - return dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0) - case .Utility: - return dispatch_get_global_queue(QOS_CLASS_UTILITY, 0) - case .Background: - return dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0) - case .Custom(let queue): + case .main: + return DispatchQueue.main + case .userInteractive: + return DispatchQueue.global(qos: DispatchQoS.QoSClass.userInteractive) + case .userInitiated: + return DispatchQueue.global(qos: DispatchQoS.QoSClass.userInitiated) + case .utility: + return DispatchQueue.global(qos: DispatchQoS.QoSClass.utility) + case .background: + return DispatchQueue.global(qos: DispatchQoS.QoSClass.background) + case .custom(let queue): return queue } } - static public func getCollectionQueue() -> DispatchQueue { - return .Custom(q) + static public func getCollectionQueue() -> AsyncQueue { + return .custom(q) } } -let q = dispatch_queue_create("com.asynctask.serial.queue", DISPATCH_QUEUE_SERIAL); +let q = DispatchQueue(label: "com.asynctask.serial.queue", attributes: []); diff --git a/Source/Base/Helper.swift b/Source/Base/Helper.swift index 867bde0..5ddd5b7 100644 --- a/Source/Base/Helper.swift +++ b/Source/Base/Helper.swift @@ -3,13 +3,17 @@ // Pods // // Created by Zhixuan Lai on 3/1/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation -internal extension dispatch_time_t { - init(timeInterval: NSTimeInterval) { - self.init(timeInterval < NSTimeInterval(0) ? DISPATCH_TIME_FOREVER : dispatch_time(DISPATCH_TIME_NOW, Int64(timeInterval * Double(NSEC_PER_SEC)))) +internal extension DispatchTime { + init(timeInterval: TimeInterval) { + + + let timeVal = timeInterval < TimeInterval(0) ? DispatchTime.distantFuture : DispatchTime.now() + Double(Int64(timeInterval * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC) + + self.init(uptimeNanoseconds: timeVal.uptimeNanoseconds) } } diff --git a/Source/Base/Task.swift b/Source/Base/Task.swift index 5f8ae47..74ec276 100644 --- a/Source/Base/Task.swift +++ b/Source/Base/Task.swift @@ -3,7 +3,7 @@ // Pods // // Created by Zhixuan Lai on 5/27/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation @@ -11,9 +11,9 @@ import Foundation public protocol TaskType { associatedtype ReturnType - func action(completion: ReturnType -> ()) - func async(queue: DispatchQueue, completion: ReturnType -> ()) - func await(queue: DispatchQueue) -> ReturnType + func action(_ completion: @escaping ( ReturnType) -> ()) + func async(_ queue: AsyncQueue, completion: @escaping (ReturnType) -> ()) + func await(_ queue: AsyncQueue) -> ReturnType } extension TaskType { @@ -21,38 +21,38 @@ extension TaskType { public var throwableTask: ThrowableTask { return ThrowableTask{callback in self.action {result in - callback(Result.Success(result)) + callback(Result.success(result)) } } } - public func async(queue: DispatchQueue = DefaultQueue, completion: (ReturnType -> ()) = {_ in}) { + public func async(_ queue: AsyncQueue = DefaultQueue, completion: @escaping ((ReturnType) -> ()) = {_ in}) { throwableTask.asyncResult(queue) {result in - if case let .Success(r) = result { + if case let .success(r) = result { completion(r) } } } - public func await(queue: DispatchQueue = DefaultQueue) -> ReturnType { + public func await(_ queue: AsyncQueue = DefaultQueue) -> ReturnType { return try! throwableTask.awaitResult(queue).extract() } } -public class Task : TaskType { +open class Task : TaskType { - public let action: (ReturnType -> ()) -> () + open let action: (@escaping (ReturnType) -> ()) -> () - public func action(completion: ReturnType -> ()) { + open func action(_ completion: @escaping (ReturnType) -> ()) { action(completion) } - public init(action anAction: (ReturnType -> ()) -> ()) { + public init(action anAction: @escaping ( @escaping (ReturnType) -> ()) -> ()) { action = anAction } - public convenience init(action anAction: () -> ReturnType) { + public convenience init(action anAction: @escaping () -> ReturnType) { self.init {callback in callback(anAction())} } diff --git a/Source/Base/ThrowableTask.swift b/Source/Base/ThrowableTask.swift index a177bd5..d552e33 100644 --- a/Source/Base/ThrowableTask.swift +++ b/Source/Base/ThrowableTask.swift @@ -3,21 +3,21 @@ // Pods // // Created by Zhixuan Lai on 6/1/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation public enum Result { - case Success(ReturnType) - case Failure(ErrorType) + case success(ReturnType) + case failure(Error) public func extract() throws -> ReturnType { switch self { - case .Success(let value): + case .success(let value): return value - case .Failure(let error): + case .failure(let error): throw error } } @@ -27,78 +27,78 @@ public enum Result { public protocol ThrowableTaskType { associatedtype ReturnType - func action(completion: Result -> ()) - func asyncResult(queue: DispatchQueue, completion: Result -> ()) - func awaitResult(queue: DispatchQueue) -> Result - func await(queue: DispatchQueue) throws -> ReturnType + func action(_ completion: @escaping (Result) -> ()) + func asyncResult(_ queue: AsyncQueue, completion: @escaping (Result) -> ()) + func awaitResult(_ queue: AsyncQueue) -> Result + func await(_ queue: AsyncQueue) throws -> ReturnType } extension ThrowableTaskType { - public func asyncResult(queue: DispatchQueue = DefaultQueue, completion: (Result -> ()) = {_ in}) { - dispatch_async(queue.get()) { + public func asyncResult(_ queue: AsyncQueue = DefaultQueue, completion: @escaping ((Result) -> ()) = {_ in}) { + queue.get().async { self.action(completion) } } - public func awaitResult(queue: DispatchQueue = DefaultQueue) -> Result { - let timeout = dispatch_time_t(timeInterval: TimeoutForever) + public func awaitResult(_ queue: AsyncQueue = DefaultQueue) -> Result { + let timeout = DispatchTime(timeInterval: TimeoutForever) var value: Result? - let fd_sema = dispatch_semaphore_create(0) + let fd_sema = DispatchSemaphore(value: 0) - dispatch_async(queue.get()) { + queue.get().async { self.action {result in value = result - dispatch_semaphore_signal(fd_sema) + fd_sema.signal() } } - dispatch_semaphore_wait(fd_sema, timeout) + _ = fd_sema.wait(timeout: timeout) return value! } - public func await(queue: DispatchQueue = DefaultQueue) throws -> ReturnType { + public func await(_ queue: AsyncQueue = DefaultQueue) throws -> ReturnType { return try awaitResult(queue).extract() } } -public class ThrowableTask : ThrowableTaskType { +open class ThrowableTask : ThrowableTaskType { - public let action: (Result -> ()) -> () + open let action: (@escaping ( Result) -> ()) -> () - public func action(completion: Result -> ()) { + open func action(_ completion: @escaping (Result) -> ()) { action(completion) } - public init(action anAction: (Result -> ()) -> ()) { + public init(action anAction: @escaping ( @escaping (Result) -> ()) -> ()) { action = anAction } - public convenience init(action: () -> Result) { + public convenience init(action: @escaping () -> Result) { self.init {callback in callback(action())} } - public convenience init(action: (ReturnType -> ()) throws -> ()) { - self.init {(callback: Result -> ()) in + public convenience init(action: @escaping ((ReturnType) -> ()) throws -> ()) { + self.init {(callback: (Result) -> ()) in do { try action {result in - callback(Result.Success(result)) + callback(Result.success(result)) } } catch { - callback(Result.Failure(error)) + callback(Result.failure(error)) } } } - public convenience init(action: () throws -> ReturnType) { - self.init {(callback: Result -> ()) in + public convenience init(action: @escaping () throws -> ReturnType) { + self.init {(callback: (Result) -> ()) in do { - callback(Result.Success(try action())) + callback(Result.success(try action())) } catch { - callback(Result.Failure(error)) + callback(Result.failure(error)) } } } diff --git a/Source/Base/Thunkify.swift b/Source/Base/Thunkify.swift index 5eb9378..150fd33 100644 --- a/Source/Base/Thunkify.swift +++ b/Source/Base/Thunkify.swift @@ -3,23 +3,23 @@ // Pods // // Created by Zhixuan Lai on 5/27/16. -// +// Converted to Swift 3 by Tom Kroening 4/11/2017 // import Foundation -public func thunkify(function: (A, T -> Void) -> Void) -> (A -> Task) { +public func thunkify(_ function: @escaping (A, (T) -> Void) -> Void) -> ((A) -> Task) { return {a in Task {callback in function(a, callback) } } } -public func thunkify(function: (A, B, T -> Void) -> Void) -> ((A, B) -> Task) { +public func thunkify(_ function: @escaping (A, B, (T) -> Void) -> Void) -> ((A, B) -> Task) { return {a, b in Task {callback in function(a, b, callback) } } } -public func thunkify(function: (A, B, C, T -> ()) -> ()) -> ((A, B, C) -> Task) { +public func thunkify(_ function: @escaping (A, B, C, (T) -> ()) -> ()) -> ((A, B, C) -> Task) { return {a, b, c in Task {callback in function(a, b, c, callback) } } } -public func thunkify(function: (A, B, C, D, T -> ()) -> ()) -> ((A, B, C, D) -> Task) { +public func thunkify(_ function: @escaping (A, B, C, D, (T) -> ()) -> ()) -> ((A, B, C, D) -> Task) { return {a, b, c, d in Task {callback in function(a, b, c, d, callback) } } } diff --git a/Tests/DispatchQueue.swift b/Tests/DispatchQueue.swift index 70db54c..125f58b 100644 --- a/Tests/DispatchQueue.swift +++ b/Tests/DispatchQueue.swift @@ -9,38 +9,38 @@ class DispatchQueueSpec: QuickSpec { // waiting on the current thread creates dead lock Task() { #if (arch(i386) || arch(x86_64)) && (os(iOS) || os(tvOS)) // Simulator - expect(NSThread.isMainThread()) == true + expect(Thread.isMainThread()) == true #else expect(qos_class_self()) == qos_class_main() #endif - }.async(.Main) + }.async(.main) Task() { expect(qos_class_self()) == QOS_CLASS_USER_INTERACTIVE - }.async(.UserInteractive) + }.async(.userInteractive) Task() { expect(qos_class_self()) == QOS_CLASS_USER_INITIATED - }.async(.UserInitiated) + }.async(.userInitiated) Task() { expect(qos_class_self()) == QOS_CLASS_UTILITY - }.async(.Utility) + }.async(.utility) Task() { expect(qos_class_self()) == QOS_CLASS_BACKGROUND - }.async(.Background) + }.async(.background) - let customQueue = dispatch_queue_create("CustomQueueLabel", DISPATCH_QUEUE_CONCURRENT) + let customQueue = DispatchQueue(label: "CustomQueueLabel") Task() { let currentClass = qos_class_self() let isValidClass = currentClass == qos_class_main() || currentClass == QOS_CLASS_USER_INITIATED expect(isValidClass) == true // TODO: Test for current queue label. dispatch_get_current_queue is unavailable in Swift, so we cant' use the return value from and pass it to dispatch_queue_get_label. - }.await(.Custom(customQueue)) + }.await(.custom(customQueue)) waitUntil { done in - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) done() } } diff --git a/Tests/Helper.swift b/Tests/Helper.swift index 35e3ae9..c6a857e 100644 --- a/Tests/Helper.swift +++ b/Tests/Helper.swift @@ -8,25 +8,25 @@ import Foundation -extension CollectionType { - /// Return a copy of `self` with its elements shuffled - func shuffle() -> [Generator.Element] { - var list = Array(self) - list.shuffleInPlace() - return list - } -} - -extension MutableCollectionType where Index == Int { - /// Shuffle the elements of `self` in-place. - mutating func shuffleInPlace() { - // empty and single-element collections don't shuffle - if count < 2 { return } - - for i in 0.. [Iterator.Element] { +// var list = Array(self) +// list.shuffleInPlace() +// return list +// } +//} +// +//extension MutableCollection where Index == Int { +// /// Shuffle the elements of `self` in-place. +// mutating func shuffleInPlace() { +// // empty and single-element collections don't shuffle +// if count < 2 { return } +// +// for i in 0.. String { - NSThread.sleepForTimeInterval(0.1) + func encode(_ message: String) -> String { + Thread.sleep(forTimeInterval: 0.1) return message } - func encryptMessage(message: String) -> Task { + func encryptMessage(_ message: String) -> Task { return Task { encode(message) } @@ -26,17 +26,19 @@ class TaskSpec: QuickSpec { } it("can wrap asynchronous APIs") { - let session = NSURLSession(configuration: .ephemeralSessionConfiguration()) + let session = URLSession(configuration: .ephemeral) - let get = {(URL: NSURL) in - Task { session.dataTaskWithURL(URL, completionHandler: $0).resume() } + let get = {(url: URL) in + Task { session.dataTask(with: url, completionHandler: $0).resume() } } - let URL = NSURL(string: "https://httpbin.org/delay/1")! - let (data, response, error) = get(URL).await() - expect(data).to(beTruthy()) - expect(response).to(beTruthy()) - expect(response!.URL!.absoluteString) == "https://httpbin.org/delay/1" + let url = URL(string: "https://httpbin.org/delay/1")! + let (data, response, error) = get(url).await() + + expect(data).toNot(beNil()) + expect(response).toNot(beNil()) + + expect(response!.url!.absoluteString) == "https://httpbin.org/delay/1" expect(error).to(beNil()) } } diff --git a/Tests/ThrowableTask.swift b/Tests/ThrowableTask.swift index 06278f0..bd0712b 100644 --- a/Tests/ThrowableTask.swift +++ b/Tests/ThrowableTask.swift @@ -5,20 +5,20 @@ import AsyncTask class ThrowableTaskSpec: QuickSpec { override func spec() { it("should throw") { - enum Error: ErrorType { - case NotFound + enum TestError: Error { + case notFound } let load = {(path: String) -> ThrowableTask in ThrowableTask { - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) switch path { case "profile.png": return NSData() case "index.html": return NSData() default: - throw Error.NotFound + throw TestError.notFound } } } diff --git a/Tests/TrivialExample.swift b/Tests/TrivialExample.swift index 445de56..51569c9 100644 --- a/Tests/TrivialExample.swift +++ b/Tests/TrivialExample.swift @@ -8,7 +8,7 @@ class TrivialExampleSpec: QuickSpec { it("can take optional value") { let load = {(path: String) -> Task in Task { - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) switch path { case "profile.png": return NSData() @@ -20,20 +20,20 @@ class TrivialExampleSpec: QuickSpec { } } - expect(load("profile.png").await()).to(beTruthy()) - expect(load("index.html").await()).to(beTruthy()) + expect(load("profile.png").await()).toNot(beNil()) + expect(load("index.html").await()).toNot(beNil()) expect(load("random.txt").await()).to(beNil()) } it("can be nested") { let emptyString = Task { - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) return "" } let appendString = {(a: String, b: String) -> Task in Task { - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) return a + b } } @@ -74,7 +74,7 @@ class TrivialExampleSpec: QuickSpec { var a = 0 Task { - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) expect(a) == 0 a = 1 expect(a) == 1 @@ -84,14 +84,14 @@ class TrivialExampleSpec: QuickSpec { expect(a).toEventually(equal(1), timeout: 3) waitUntil { done in - NSThread.sleepForTimeInterval(0.5) + Thread.sleep(forTimeInterval: 0.5) done() } } it("should return result in callback") { let echo = Task {() -> String in - NSThread.sleepForTimeInterval(0.05) + Thread.sleep(forTimeInterval: 0.05) return "Hello" } @@ -100,7 +100,7 @@ class TrivialExampleSpec: QuickSpec { } waitUntil { done in - NSThread.sleepForTimeInterval(0.5) + Thread.sleep(forTimeInterval: 0.5) done() } } @@ -108,13 +108,13 @@ class TrivialExampleSpec: QuickSpec { it("can wait synchronously") { var a = 0 - Task { NSThread.sleepForTimeInterval(0.05); expect(a) == 1 }.async() + Task { Thread.sleep(forTimeInterval: 0.05); expect(a) == 1 }.async() Task {expect(a) == 0}.await() a = 1 waitUntil { done in - NSThread.sleepForTimeInterval(0.5) + Thread.sleep(forTimeInterval: 0.5) done() } }