From f94810ee34c60343bd7fcc54d8680bd1c85adbea Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Tue, 31 Oct 2017 21:19:26 +0900 Subject: [PATCH 1/3] Migrate to Swift 4 --- Package.swift | 2 +- ReactiveTask.xcodeproj/project.pbxproj | 20 ++++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Package.swift b/Package.swift index 75c6e47..b8ccca4 100644 --- a/Package.swift +++ b/Package.swift @@ -16,5 +16,5 @@ let package = Package( .target(name: "ReactiveTask", dependencies: ["Result", "ReactiveSwift"], path: "Sources"), .testTarget(name: "ReactiveTaskTests", dependencies: ["ReactiveTask", "Quick", "Nimble"]), ], - swiftLanguageVersions: [3] + swiftLanguageVersions: [4] ) diff --git a/ReactiveTask.xcodeproj/project.pbxproj b/ReactiveTask.xcodeproj/project.pbxproj index 519eedb..c733f5c 100644 --- a/ReactiveTask.xcodeproj/project.pbxproj +++ b/ReactiveTask.xcodeproj/project.pbxproj @@ -370,7 +370,8 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; - SWIFT_VERSION = 2.3; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -390,7 +391,8 @@ GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; - SWIFT_VERSION = 2.3; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -406,7 +408,6 @@ INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -420,7 +421,6 @@ INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Release; }; @@ -435,7 +435,6 @@ INFOPLIST_FILE = Tests/ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -450,7 +449,6 @@ INFOPLIST_FILE = Tests/ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Release; }; @@ -468,7 +466,8 @@ GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; - SWIFT_VERSION = 2.3; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -484,7 +483,6 @@ INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Test; }; @@ -499,7 +497,6 @@ INFOPLIST_FILE = Tests/ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Test; }; @@ -517,7 +514,8 @@ GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; - SWIFT_VERSION = 2.3; + SWIFT_SWIFT3_OBJC_INFERENCE = Off; + SWIFT_VERSION = 4.0; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; }; @@ -533,7 +531,6 @@ INFOPLIST_FILE = Sources/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Profile; }; @@ -548,7 +545,6 @@ INFOPLIST_FILE = Tests/ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; }; name = Profile; }; From 960e638d20af9cb04c8e4fe79b0e66167a47eedd Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Tue, 31 Oct 2017 21:49:50 +0900 Subject: [PATCH 2/3] Use UnsafeRawBufferPointer to address a deprecation warning --- Sources/Task.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Task.swift b/Sources/Task.swift index e69efdf..09e1a02 100644 --- a/Sources/Task.swift +++ b/Sources/Task.swift @@ -235,7 +235,7 @@ private final class Pipe { signal.observe(Signal.Observer(value: { data in let dispatchData = data.withUnsafeBytes { (bytes: UnsafePointer) -> DispatchData in - let buffer = UnsafeBufferPointer(start: bytes, count: data.count) + let buffer = UnsafeRawBufferPointer(start: bytes, count: data.count) return DispatchData(bytes: buffer) } From 62d102497c15320cdadc423b1776a05a5ffcb7fc Mon Sep 17 00:00:00 2001 From: Sho Ikeda Date: Tue, 31 Oct 2017 21:57:51 +0900 Subject: [PATCH 3/3] Cast DispatchData to Data https://gist.github.com/mayoff/6e35e263b9ddd04d9b77e5261212be19 --- Sources/Task.swift | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Sources/Task.swift b/Sources/Task.swift index 09e1a02..10edd04 100644 --- a/Sources/Task.swift +++ b/Sources/Task.swift @@ -180,12 +180,10 @@ private final class Pipe { channel.setLimit(lowWater: 1) channel.read(offset: 0, length: Int.max, queue: self.queue) { (done, dispatchData, error) in if let dispatchData = dispatchData { - let bytes = UnsafeMutablePointer.allocate(capacity: dispatchData.count) - dispatchData.copyBytes(to: bytes, count: dispatchData.count) - let data = Data(bytes: bytes, count: dispatchData.count) - bytes.deinitialize(count: dispatchData.count) - bytes.deallocate(capacity: dispatchData.count) - + // Cast DispatchData to Data. + // See https://gist.github.com/mayoff/6e35e263b9ddd04d9b77e5261212be19. + let data = dispatchData as Any as! NSData as Data + observer.send(value: data) }