From 20790c65f22ec8004ef783ffeb6b4706d104c347 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Sun, 26 Jun 2016 23:22:23 +1000 Subject: [PATCH 01/23] Gets ReactiveCocoa to compile with Swift 3 in Xcode 8. --- .gitmodules | 6 +- Cartfile | 2 +- Cartfile.private | 6 +- Cartfile.resolved | 8 +- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/Quick | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- ReactiveTask.xcodeproj/project.pbxproj | 18 ++- ReactiveTask/Errors.swift | 8 +- ReactiveTask/Task.swift | 194 +++++++++++++------------ 11 files changed, 135 insertions(+), 115 deletions(-) diff --git a/.gitmodules b/.gitmodules index 0e96c9a..ccb593e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "Carthage/Checkouts/Nimble"] path = Carthage/Checkouts/Nimble - url = https://github.com/Quick/Nimble.git + url = https://github.com/norio-nomura/Nimble.git [submodule "Carthage/Checkouts/Quick"] path = Carthage/Checkouts/Quick - url = https://github.com/Quick/Quick.git + url = https://github.com/norio-nomura/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result - url = https://github.com/antitypical/Result.git + url = https://github.com/liscio/Result.git [submodule "Carthage/Checkouts/xcconfigs"] path = Carthage/Checkouts/xcconfigs url = https://github.com/jspahrsummers/xcconfigs.git diff --git a/Cartfile b/Cartfile index a4583d1..87745f3 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" ~> 4.2 +github "ReactiveCocoa/ReactiveCocoa" "RAC5-swift3" diff --git a/Cartfile.private b/Cartfile.private index b9e760e..5f68c3d 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ -github "Quick/Quick" ~> 0.9.2 -github "Quick/Nimble" ~> 4.0 -github "jspahrsummers/xcconfigs" ~> 0.9 +github "norio-nomura/Quick" "nn-swift-3-compatibility" +github "norio-nomura/Nimble" "nn-swift-3-compatibility" +github "jspahrsummers/xcconfigs" ~> 0.9 \ No newline at end of file diff --git a/Cartfile.resolved b/Cartfile.resolved index 7906b50..467bd6d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "Quick/Nimble" "v4.0.0" -github "Quick/Quick" "v0.9.2" -github "antitypical/Result" "2.0.0" +github "norio-nomura/Nimble" "fd248426eb8692b4616c2b842fcb9a2579b964e8" +github "norio-nomura/Quick" "d3980a8bbafb13a973cb3018490e6577ee8307fd" +github "liscio/Result" "e96316e6afabd5e1f1389571babc3cfee5edb5b9" github "jspahrsummers/xcconfigs" "0.9" -github "ReactiveCocoa/ReactiveCocoa" "v4.2.0" +github "ReactiveCocoa/ReactiveCocoa" "32b08cec7a280535115c780b30fb17214618a493" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 29f7fb3..fd24842 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 29f7fb3732893f76fa851cb37b0c4b339c49cead +Subproject commit fd248426eb8692b4616c2b842fcb9a2579b964e8 diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick index dc2b4b7..d3980a8 160000 --- a/Carthage/Checkouts/Quick +++ b/Carthage/Checkouts/Quick @@ -1 +1 @@ -Subproject commit dc2b4b75d2f718518acbdef289a72fad77975a8a +Subproject commit d3980a8bbafb13a973cb3018490e6577ee8307fd diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 5cfcdcc..32b08ce 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 5cfcdccdcc693e7d685b4f7b7cf2c2ccf5c59c8d +Subproject commit 32b08cec7a280535115c780b30fb17214618a493 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index 5dec9cf..e96316e 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit 5dec9cf225d5fa3b0602679fb2638e40191da46b +Subproject commit e96316e6afabd5e1f1389571babc3cfee5edb5b9 diff --git a/ReactiveTask.xcodeproj/project.pbxproj b/ReactiveTask.xcodeproj/project.pbxproj index 2d309bc..d401b5d 100644 --- a/ReactiveTask.xcodeproj/project.pbxproj +++ b/ReactiveTask.xcodeproj/project.pbxproj @@ -274,9 +274,11 @@ TargetAttributes = { D0BFEA571A2D1E5E00E23194 = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0800; }; D0BFEA621A2D1E5E00E23194 = { CreatedOnToolsVersion = 6.1.1; + LastSwiftMigration = 0800; }; }; }; @@ -351,7 +353,7 @@ CURRENT_PROJECT_VERSION = 1; ENABLE_TESTABILITY = YES; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; @@ -365,7 +367,7 @@ buildSettings = { CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -382,6 +384,7 @@ INFOPLIST_FILE = ReactiveTask/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -395,6 +398,7 @@ INFOPLIST_FILE = ReactiveTask/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -409,6 +413,7 @@ INFOPLIST_FILE = ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -423,6 +428,7 @@ INFOPLIST_FILE = ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -432,7 +438,7 @@ buildSettings = { CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -449,6 +455,7 @@ INFOPLIST_FILE = ReactiveTask/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Test; }; @@ -463,6 +470,7 @@ INFOPLIST_FILE = ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Test; }; @@ -472,7 +480,7 @@ buildSettings = { CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.9; + MACOSX_DEPLOYMENT_TARGET = 10.10; SDKROOT = macosx; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -489,6 +497,7 @@ INFOPLIST_FILE = ReactiveTask/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Profile; }; @@ -503,6 +512,7 @@ INFOPLIST_FILE = ReactiveTaskTests/Info.plist; PRODUCT_BUNDLE_IDENTIFIER = "org.carthage.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Profile; }; diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index 30c0e23..6d5abbf 100644 --- a/ReactiveTask/Errors.swift +++ b/ReactiveTask/Errors.swift @@ -10,9 +10,9 @@ import Foundation import ReactiveCocoa /// An error originating from ReactiveTask. -public enum TaskError: ErrorType, Equatable { +public enum TaskError: ErrorProtocol, Equatable { /// A shell task exited unsuccessfully. - case ShellTaskFailed(Task, exitCode: Int32, standardError: String?) + case shellTaskFailed(Task, exitCode: Int32, standardError: String?) /// An error was returned from a POSIX API. case POSIXError(Int32) @@ -21,7 +21,7 @@ public enum TaskError: ErrorType, Equatable { extension TaskError: CustomStringConvertible { public var description: String { switch self { - case let .ShellTaskFailed(task, exitCode, standardError): + case let .shellTaskFailed(task, exitCode, standardError): var description = "A shell task (\(task)) failed with exit code \(exitCode)" if let standardError = standardError { description += ":\n\(standardError)" @@ -37,7 +37,7 @@ extension TaskError: CustomStringConvertible { public func == (lhs: TaskError, rhs: TaskError) -> Bool { switch (lhs, rhs) { - case let (.ShellTaskFailed(lhsTask, lhsCode, lhsErr), .ShellTaskFailed(rhsTask, rhsCode, rhsErr)): + case let (.shellTaskFailed(lhsTask, lhsCode, lhsErr), .shellTaskFailed(rhsTask, rhsCode, rhsErr)): return lhsTask == rhsTask && lhsCode == rhsCode && lhsErr == rhsErr case let (.POSIXError(lhsCode), .POSIXError(rhsCode)): diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index d2fa1fb..ace953e 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -38,17 +38,17 @@ public struct Task { } /// A GCD group which to wait completion - private static let group = dispatch_group_create() + private static let group = DispatchGroup() /// wait for all task termination public static func waitForAllTaskTermination() { - dispatch_group_wait(Task.group, DISPATCH_TIME_FOREVER) + Task.group.wait(timeout: DispatchTime.distantFuture) } } extension Task: CustomStringConvertible { public var description: String { - return "\(launchPath) \(arguments.joinWithSeparator(" "))" + return "\(launchPath) \(arguments.joined(separator: " "))" } } @@ -70,7 +70,7 @@ private func ==(lhs: [Key: Value]?, rhs: [Key: case let (lhs?, rhs?): return lhs == rhs - case (.None, .None): + case (.none, .none): return true default: @@ -84,7 +84,7 @@ public func ==(lhs: Task, rhs: Task) -> Bool { /// A private class used to encapsulate a Unix pipe. private final class Pipe { - typealias ReadProducer = SignalProducer + typealias ReadProducer = SignalProducer /// The file descriptor for reading data. let readFD: Int32 @@ -93,25 +93,25 @@ private final class Pipe { let writeFD: Int32 /// A GCD queue upon which to deliver I/O callbacks. - let queue: dispatch_queue_t + let queue: DispatchQueue /// A GCD group which to wait completion - let group: dispatch_group_t + let group: DispatchGroup /// Creates an NSFileHandle corresponding to the `readFD`. The file handle /// will not automatically close the descriptor. - var readHandle: NSFileHandle { - return NSFileHandle(fileDescriptor: readFD, closeOnDealloc: false) + var readHandle: FileHandle { + return FileHandle(fileDescriptor: readFD, closeOnDealloc: false) } /// Creates an NSFileHandle corresponding to the `writeFD`. The file handle /// will not automatically close the descriptor. - var writeHandle: NSFileHandle { - return NSFileHandle(fileDescriptor: writeFD, closeOnDealloc: false) + var writeHandle: FileHandle { + return FileHandle(fileDescriptor: writeFD, closeOnDealloc: false) } /// Initializes a pipe object using existing file descriptors. - init(readFD: Int32, writeFD: Int32, queue: dispatch_queue_t, group: dispatch_group_t) { + init(readFD: Int32, writeFD: Int32, queue: DispatchQueue, group: DispatchGroup) { precondition(readFD >= 0) precondition(writeFD >= 0) @@ -122,7 +122,8 @@ private final class Pipe { } /// Instantiates a new descriptor pair. - class func create(queue: dispatch_queue_t, _ group: dispatch_group_t) -> Result { + //TODO: Swift 3 API guidelines? + class func create(_ queue: DispatchQueue, _ group: DispatchGroup) -> Result { var fildes: [Int32] = [ 0, 0 ] if pipe(&fildes) == 0 { return .Success(self.init(readFD: fildes[0], writeFD: fildes[1], queue: queue, group: group)) @@ -144,8 +145,8 @@ private final class Pipe { /// anywhere else, as it may close unexpectedly. func transferReadsToProducer() -> ReadProducer { return SignalProducer { observer, disposable in - dispatch_group_enter(self.group) - let channel = dispatch_io_create(DISPATCH_IO_STREAM, self.readFD, self.queue) { error in + self.group.enter() + let channel = DispatchIO(type: .stream, fileDescriptor: self.readFD, queue: self.queue) { error in if error == 0 { observer.sendCompleted() } else if error == ECANCELED { @@ -155,13 +156,16 @@ private final class Pipe { } close(self.readFD) - dispatch_group_leave(self.group) + self.group.leave() } - dispatch_io_set_low_water(channel, 1) - dispatch_io_read(channel, 0, Int.max, self.queue) { (done, data, error) in - if let data = data { - observer.sendNext(data as! NSData) + 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(allocatingCapacity: dispatchData.count) + dispatchData.copyBytes(to: bytes, count: dispatchData.count) + let data = Data(bytes: bytes, count: dispatchData.count) + observer.sendNext(data) } if error == ECANCELED { @@ -171,12 +175,12 @@ private final class Pipe { } if done { - dispatch_io_close(channel, 0) + channel.close() } } disposable.addDisposable { - dispatch_io_close(channel, DISPATCH_IO_STOP) + channel.close(flags: .stop) } } } @@ -189,10 +193,11 @@ private final class Pipe { /// anywhere else, as it may close unexpectedly. /// /// Returns a producer that will complete or error. - func writeDataFromProducer(producer: SignalProducer) -> SignalProducer<(), TaskError> { + //TODO: Swift 3 API guidelines? + func writeDataFromProducer(_ producer: SignalProducer) -> SignalProducer<(), TaskError> { return SignalProducer { observer, disposable in - dispatch_group_enter(self.group) - let channel = dispatch_io_create(DISPATCH_IO_STREAM, self.writeFD, self.queue) { error in + self.group.enter() + let channel = DispatchIO(type: .stream, fileDescriptor: self.writeFD, queue: self.queue) { error in if error == 0 { observer.sendCompleted() } else if error == ECANCELED { @@ -202,16 +207,18 @@ private final class Pipe { } close(self.writeFD) - dispatch_group_leave(self.group) + self.group.leave() } producer.startWithSignal { signal, producerDisposable in disposable.addDisposable(producerDisposable) signal.observe(Observer(next: { data in - let dispatchData = dispatch_data_create(data.bytes, data.length, self.queue, nil) - - dispatch_io_write(channel, 0, dispatchData, self.queue) { (done, data, error) in + let bytes = UnsafeMutablePointer(allocatingCapacity: data.count) + data.copyBytes(to: bytes, count: data.count) + let buffer = UnsafeBufferPointer(start: bytes, count: data.count) + let dispatchData = DispatchData(bytes: buffer) + channel.write(offset: 0, data: dispatchData, queue: self.queue) { (done, data, error) in if error == ECANCELED { observer.sendInterrupted() } else if error != 0 { @@ -219,14 +226,14 @@ private final class Pipe { } } }, completed: { - dispatch_io_close(channel, 0) + channel.close() }, interrupted: { observer.sendInterrupted() })) } disposable.addDisposable { - dispatch_io_close(channel, DISPATCH_IO_STOP) + channel.close(flags: .stop) } } } @@ -240,83 +247,83 @@ public protocol TaskEventType { var value: T? { get } /// Maps over the value embedded in a `Success` event. - func map(@noescape transform: T -> U) -> TaskEvent + func map( _ transform: @noescape(T) -> U) -> TaskEvent /// Convenience operator for mapping TaskEvents to SignalProducers. - func producerMap(@noescape transform: T -> SignalProducer) -> SignalProducer, Error> + func producerMap( _ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> } /// Represents events that can occur during the execution of a task that is /// expected to terminate with a result of type T (upon success). public enum TaskEvent: TaskEventType { /// The task is about to be launched. - case Launch(Task) + case launch(Task) /// Some data arrived from the task on `stdout`. - case StandardOutput(NSData) + case standardOutput(Data) /// Some data arrived from the task on `stderr`. - case StandardError(NSData) + case standardError(Data) /// The task exited successfully (with status 0), and value T was produced /// as a result. - case Success(T) + case success(T) /// The resulting value, if the event is `Success`. public var value: T? { - if case let .Success(value) = self { + if case let .success(value) = self { return value } return nil } /// Maps over the value embedded in a `Success` event. - public func map(@noescape transform: T -> U) -> TaskEvent { + public func map( _ transform: @noescape(T) -> U) -> TaskEvent { switch self { - case let .Launch(task): - return .Launch(task) + case let .launch(task): + return .launch(task) - case let .StandardOutput(data): - return .StandardOutput(data) + case let .standardOutput(data): + return .standardOutput(data) - case let .StandardError(data): - return .StandardError(data) + case let .standardError(data): + return .standardError(data) - case let .Success(value): - return .Success(transform(value)) + case let .success(value): + return .success(transform(value)) } } /// Convenience operator for mapping TaskEvents to SignalProducers. - public func producerMap(@noescape transform: T -> SignalProducer) -> SignalProducer, Error> { + public func producerMap( _ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> { switch self { - case let .Launch(task): - return .init(value: .Launch(task)) + case let .launch(task): + return .init(value: .launch(task)) - case let .StandardOutput(data): - return .init(value: .StandardOutput(data)) + case let .standardOutput(data): + return .init(value: .standardOutput(data)) - case let .StandardError(data): - return .init(value: .StandardError(data)) + case let .standardError(data): + return .init(value: .standardError(data)) - case let .Success(value): - return transform(value).map(TaskEvent.Success) + case let .success(value): + return transform(value).map(TaskEvent.success) } } } public func == (lhs: TaskEvent, rhs: TaskEvent) -> Bool { switch (lhs, rhs) { - case let (.Launch(left), .Launch(right)): + case let (.launch(left), .launch(right)): return left == right - case let (.StandardOutput(left), .StandardOutput(right)): + case let (.standardOutput(left), .standardOutput(right)): return left == right - case let (.StandardError(left), .StandardError(right)): + case let (.standardError(left), .standardError(right)): return left == right - case let (.Success(left), .Success(right)): + case let (.success(left), .success(right)): return left == right default: @@ -326,21 +333,22 @@ public func == (lhs: TaskEvent, rhs: TaskEvent) -> Bool { extension TaskEvent: CustomStringConvertible { public var description: String { - func dataDescription(data: NSData) -> String { - return NSString(data: data, encoding: NSUTF8StringEncoding).map { $0 as String } ?? data.description + func dataDescription(_ data: Data) -> String { + // TODO: Check whether this can be done without NSString + return NSString(data: data, encoding: String.Encoding.utf8.rawValue).map { $0 as String } ?? data.description } switch self { - case let .Launch(task): + case let .launch(task): return "launch: \(task)" - case let .StandardOutput(data): + case let .standardOutput(data): return "stdout: " + dataDescription(data) - case let .StandardError(data): + case let .standardError(data): return "stderr: " + dataDescription(data) - case let .Success(value): + case let .success(value): return "success(\(value))" } } @@ -348,7 +356,7 @@ extension TaskEvent: CustomStringConvertible { extension SignalProducer where Value: TaskEventType { /// Maps the values inside a stream of TaskEvents into new SignalProducers. - public func flatMapTaskEvents(strategy: FlattenStrategy, transform: Value.T -> SignalProducer) -> SignalProducer, Error> { + public func flatMapTaskEvents(_ strategy: FlattenStrategy, transform: (Value.T) -> SignalProducer) -> SignalProducer, Error> { return self.flatMap(strategy) { taskEvent in return taskEvent.producerMap(transform) } @@ -382,12 +390,13 @@ extension Signal where Value: TaskEventType { /// /// - Returns: A producer that will launch the task when started, then send /// `TaskEvent`s as execution proceeds. -public func launchTask(task: Task, standardInput: SignalProducer? = nil) -> SignalProducer, TaskError> { +//TODO: Swift 3 API guidelines? +public func launchTask(_ task: Task, standardInput: SignalProducer? = nil) -> SignalProducer, TaskError> { return SignalProducer { observer, disposable in - let queue = dispatch_queue_create(task.description, DISPATCH_QUEUE_SERIAL) + let queue = DispatchQueue(label: task.description, attributes: .serial) let group = Task.group - let rawTask = NSTask() + let rawTask = Foundation.Task() rawTask.launchPath = task.launchPath rawTask.arguments = task.arguments @@ -417,22 +426,22 @@ public func launchTask(task: Task, standardInput: SignalProducer SignalProducer, TaskError> in + .flatMap(.merge) { stdoutPipe, stderrPipe -> SignalProducer, TaskError> in let stdoutProducer = stdoutPipe.transferReadsToProducer() let stderrProducer = stderrPipe.transferReadsToProducer() enum Aggregation { - case Value(NSData) - case Failed(TaskError) - case Interrupted + case value(Data) + case failed(TaskError) + case interrupted var producer: Pipe.ReadProducer { switch self { - case let .Value(data): + case let .value(data): return .init(value: data) - case let .Failed(error): + case let .failed(error): return .init(error: error) - case .Interrupted: + case .interrupted: return SignalProducer { observer, _ in observer.sendInterrupted() } @@ -441,29 +450,30 @@ public func launchTask(task: Task, standardInput: SignalProducer Pipe.ReadProducer { + //TODO: Swift 3 API guidelines? + func startAggregating(_ producer: Pipe.ReadProducer) -> Pipe.ReadProducer { let aggregated = MutableProperty(nil) producer.startWithSignal { signal, signalDisposable in disposable += signalDisposable - let aggregate = NSMutableData() + var aggregate = Data() signal.observe(Observer(next: { data in - observer.sendNext(.StandardOutput(data)) - aggregate.appendData(data) + observer.sendNext(.standardOutput(data)) + aggregate.append(data) }, failed: { error in observer.sendFailed(error) - aggregated.value = .Failed(error) + aggregated.value = .failed(error) }, completed: { - aggregated.value = .Value(aggregate) + aggregated.value = .value(aggregate) }, interrupted: { - aggregated.value = .Interrupted + aggregated.value = .interrupted })) } return aggregated.producer .ignoreNil() - .flatMap(.Concat) { $0.producer } + .flatMap(.concat) { $0.producer } } let stdoutAggregated = startAggregating(stdoutProducer) @@ -472,7 +482,7 @@ public func launchTask(task: Task, standardInput: SignalProducer SignalProducer, TaskError> in - let errorString = (data.length > 0 ? NSString(data: data, encoding: NSUTF8StringEncoding) as? String : nil) - return SignalProducer(error: .ShellTaskFailed(task, exitCode: terminationStatus, standardError: errorString)) + .flatMap(.concat) { data -> SignalProducer, TaskError> in + let errorString = (data.count > 0 ? NSString(data: data, encoding: String.Encoding.utf8.rawValue) as? String : nil) + return SignalProducer(error: .shellTaskFailed(task, exitCode: terminationStatus, standardError: errorString)) } .start(observer) } - dispatch_group_leave(group) + group.leave() } - observer.sendNext(.Launch(task)) + observer.sendNext(.launch(task)) rawTask.launch() close(stdoutPipe.writeFD) close(stderrPipe.writeFD) From 79ae0d40a3a7fd8d4e74b85df2b78f0fd9da24b4 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 27 Jun 2016 22:19:40 +1000 Subject: [PATCH 02/23] Renamed TaskError.POSIXError to TaskError.posixError. --- ReactiveTask/Errors.swift | 8 ++++---- ReactiveTask/Task.swift | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index 6d5abbf..1691547 100644 --- a/ReactiveTask/Errors.swift +++ b/ReactiveTask/Errors.swift @@ -15,7 +15,7 @@ public enum TaskError: ErrorProtocol, Equatable { case shellTaskFailed(Task, exitCode: Int32, standardError: String?) /// An error was returned from a POSIX API. - case POSIXError(Int32) + case posixError(Int32) } extension TaskError: CustomStringConvertible { @@ -29,8 +29,8 @@ extension TaskError: CustomStringConvertible { return description - case let .POSIXError(code): - return NSError(domain: NSPOSIXErrorDomain, code: Int(code), userInfo: nil).description + case let .posixError(code): + return NSError(domain: NSposixErrorDomain, code: Int(code), userInfo: nil).description } } } @@ -40,7 +40,7 @@ public func == (lhs: TaskError, rhs: TaskError) -> Bool { case let (.shellTaskFailed(lhsTask, lhsCode, lhsErr), .shellTaskFailed(rhsTask, rhsCode, rhsErr)): return lhsTask == rhsTask && lhsCode == rhsCode && lhsErr == rhsErr - case let (.POSIXError(lhsCode), .POSIXError(rhsCode)): + case let (.posixError(lhsCode), .posixError(rhsCode)): return lhsCode == rhsCode default: diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index ace953e..49048be 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -128,7 +128,7 @@ private final class Pipe { if pipe(&fildes) == 0 { return .Success(self.init(readFD: fildes[0], writeFD: fildes[1], queue: queue, group: group)) } else { - return .Failure(.POSIXError(errno)) + return .Failure(.posixError(errno)) } } @@ -152,7 +152,7 @@ private final class Pipe { } else if error == ECANCELED { observer.sendInterrupted() } else { - observer.sendFailed(.POSIXError(error)) + observer.sendFailed(.posixError(error)) } close(self.readFD) @@ -171,7 +171,7 @@ private final class Pipe { if error == ECANCELED { observer.sendInterrupted() } else if error != 0 { - observer.sendFailed(.POSIXError(error)) + observer.sendFailed(.posixError(error)) } if done { @@ -203,7 +203,7 @@ private final class Pipe { } else if error == ECANCELED { observer.sendInterrupted() } else { - observer.sendFailed(.POSIXError(error)) + observer.sendFailed(.posixError(error)) } close(self.writeFD) @@ -222,7 +222,7 @@ private final class Pipe { if error == ECANCELED { observer.sendInterrupted() } else if error != 0 { - observer.sendFailed(.POSIXError(error)) + observer.sendFailed(.posixError(error)) } } }, completed: { From 95fd23a7a648c291a8f5baa6512f718aba1aa5e2 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 27 Jun 2016 22:46:05 +1000 Subject: [PATCH 03/23] Fix typo in NSPOSIXErrorDomain. --- ReactiveTask/Errors.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactiveTask/Errors.swift b/ReactiveTask/Errors.swift index 1691547..bd1bc49 100644 --- a/ReactiveTask/Errors.swift +++ b/ReactiveTask/Errors.swift @@ -30,7 +30,7 @@ extension TaskError: CustomStringConvertible { return description case let .posixError(code): - return NSError(domain: NSposixErrorDomain, code: Int(code), userInfo: nil).description + return NSError(domain: NSPOSIXErrorDomain, code: Int(code), userInfo: nil).description } } } From 0f70cce6be3270d4eddc3163db3b13a03e828ebe Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Tue, 28 Jun 2016 22:54:17 +1000 Subject: [PATCH 04/23] Add `let _ =` to get rid of unused result warnings. --- ReactiveTask/Task.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 49048be..54f72eb 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -42,7 +42,7 @@ public struct Task { /// wait for all task termination public static func waitForAllTaskTermination() { - Task.group.wait(timeout: DispatchTime.distantFuture) + let _ = Task.group.wait(timeout: DispatchTime.distantFuture) } } @@ -179,7 +179,7 @@ private final class Pipe { } } - disposable.addDisposable { + let _ = disposable.addDisposable { channel.close(flags: .stop) } } @@ -232,7 +232,7 @@ private final class Pipe { })) } - disposable.addDisposable { + let _ = disposable.addDisposable { channel.close(flags: .stop) } } @@ -515,7 +515,7 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Date: Tue, 28 Jun 2016 23:32:47 +1000 Subject: [PATCH 05/23] Minor refactoring. --- ReactiveTask/Task.swift | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 54f72eb..612c41d 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -122,7 +122,6 @@ private final class Pipe { } /// Instantiates a new descriptor pair. - //TODO: Swift 3 API guidelines? class func create(_ queue: DispatchQueue, _ group: DispatchGroup) -> Result { var fildes: [Int32] = [ 0, 0 ] if pipe(&fildes) == 0 { @@ -193,7 +192,6 @@ private final class Pipe { /// anywhere else, as it may close unexpectedly. /// /// Returns a producer that will complete or error. - //TODO: Swift 3 API guidelines? func writeDataFromProducer(_ producer: SignalProducer) -> SignalProducer<(), TaskError> { return SignalProducer { observer, disposable in self.group.enter() @@ -334,8 +332,7 @@ public func == (lhs: TaskEvent, rhs: TaskEvent) -> Bool { extension TaskEvent: CustomStringConvertible { public var description: String { func dataDescription(_ data: Data) -> String { - // TODO: Check whether this can be done without NSString - return NSString(data: data, encoding: String.Encoding.utf8.rawValue).map { $0 as String } ?? data.description + return String(data: data, encoding: String.Encoding.utf8) ?? data.description } switch self { @@ -450,7 +447,6 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Pipe.ReadProducer { let aggregated = MutableProperty(nil) From 0a7cf6d8148865d31c984c5e09843f6da5eb5eb3 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Wed, 29 Jun 2016 00:13:16 +1000 Subject: [PATCH 06/23] Updated test spec for Swift 3. All tests pass except for "should launch a task with standard input", which currently crashes. --- Carthage/Checkouts/ReactiveCocoa | 2 +- ReactiveTaskTests/TaskSpec.swift | 30 ++++++++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 32b08ce..538cec3 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 32b08cec7a280535115c780b30fb17214618a493 +Subproject commit 538cec3cf7b2f2efeff2e559ee5bc2eb4d033989 diff --git a/ReactiveTaskTests/TaskSpec.swift b/ReactiveTaskTests/TaskSpec.swift index a95584d..66f95c2 100644 --- a/ReactiveTaskTests/TaskSpec.swift +++ b/ReactiveTaskTests/TaskSpec.swift @@ -21,7 +21,7 @@ class TaskSpec: QuickSpec { let task = Task("/usr/bin/true") let result = launchTask(task) .on(next: { event in - if case let .Launch(launched) = event { + if case let .launch(launched) = event { isLaunched = true expect(launched) == task } @@ -34,41 +34,43 @@ class TaskSpec: QuickSpec { it("should launch a task that writes to stdout") { let result = launchTask(Task("/bin/echo", arguments: [ "foobar" ])) - .reduce(NSMutableData()) { aggregated, event in - if case let .StandardOutput(data) = event { - aggregated.appendData(data) + .reduce(Data()) { aggregated, event in + var mutableData = aggregated + if case let .standardOutput(data) = event { + mutableData.append(data) } - return aggregated + return mutableData } .single() expect(result).notTo(beNil()) if let data = result?.value { - expect(NSString(data: data, encoding: NSUTF8StringEncoding)).to(equal("foobar\n")) + expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("foobar\n")) } } it("should launch a task that writes to stderr") { let result = launchTask(Task("/usr/bin/stat", arguments: [ "not-a-real-file" ])) - .reduce(NSMutableData()) { aggregated, event in - if case let .StandardError(data) = event { - aggregated.appendData(data) + .reduce(Data()) { aggregated, event in + var mutableData = aggregated + if case let .standardError(data) = event { + mutableData.append(data) } - return aggregated + return mutableData } .single() expect(result).notTo(beNil()) if let data = result?.value { - expect(NSString(data: data, encoding: NSUTF8StringEncoding)).to(equal("stat: not-a-real-file: stat: No such file or directory\n")) + expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("stat: not-a-real-file: stat: No such file or directory\n")) } } it("should launch a task with standard input") { let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ] - let data = strings.map { $0.dataUsingEncoding(NSUTF8StringEncoding)! } + let data = strings.map { $0.data(using: String.Encoding.utf8)! } let result = launchTask(Task("/usr/bin/sort"), standardInput: SignalProducer(values: data)) .map { event in event.value } @@ -77,7 +79,7 @@ class TaskSpec: QuickSpec { expect(result).notTo(beNil()) if let data = result?.value { - expect(NSString(data: data, encoding: NSUTF8StringEncoding)).to(equal("bar\nbuzz\nfoo\nfuzz\n")) + expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("bar\nbuzz\nfoo\nfuzz\n")) } } @@ -88,7 +90,7 @@ class TaskSpec: QuickSpec { expect(result).notTo(beNil()) expect(result.error).notTo(beNil()) - expect(result.error) == TaskError.ShellTaskFailed(task, exitCode: 1, standardError: "stat: not-a-real-file: stat: No such file or directory\n") + expect(result.error) == TaskError.shellTaskFailed(task, exitCode: 1, standardError: "stat: not-a-real-file: stat: No such file or directory\n") if let error = result.error { expect(error.description) == "A shell task (/usr/bin/stat not-a-real-file) failed with exit code 1:\nstat: not-a-real-file: stat: No such file or directory\n" } From 004a0db07e8db74a1dfe850884276d455a8370b0 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Wed, 29 Jun 2016 00:17:18 +1000 Subject: [PATCH 07/23] Update ReactiveCocoa. --- Cartfile.resolved | 2 +- .../xcshareddata/xcschemes/ReactiveTask.xcscheme | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index 467bd6d..158b2d1 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -2,4 +2,4 @@ github "norio-nomura/Nimble" "fd248426eb8692b4616c2b842fcb9a2579b964e8" github "norio-nomura/Quick" "d3980a8bbafb13a973cb3018490e6577ee8307fd" github "liscio/Result" "e96316e6afabd5e1f1389571babc3cfee5edb5b9" github "jspahrsummers/xcconfigs" "0.9" -github "ReactiveCocoa/ReactiveCocoa" "32b08cec7a280535115c780b30fb17214618a493" +github "ReactiveCocoa/ReactiveCocoa" "538cec3cf7b2f2efeff2e559ee5bc2eb4d033989" diff --git a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme index 4fa3d93..9677cf3 100644 --- a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme +++ b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme @@ -73,6 +73,7 @@ useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" + enableThreadSanitizer = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> From a6547337cd05c0dba4a8fc710943ee6edc3ea476 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Thu, 30 Jun 2016 11:25:16 +1000 Subject: [PATCH 08/23] Clean up extraneous spaces at the beginning of functions caused by the Swift 3 migrator moving `@noescape` attributes. Abbreviate `String.Encoding.utf8` to `.utf8`. Replace one remaining use of `NSString(data:encoding:)` with `String(data:encoding:)`. Disable Thread Sanitizer. --- .../xcshareddata/xcschemes/ReactiveTask.xcscheme | 1 - ReactiveTask/Task.swift | 12 ++++++------ ReactiveTaskTests/TaskSpec.swift | 8 ++++---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme index 9677cf3..4fa3d93 100644 --- a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme +++ b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme @@ -73,7 +73,6 @@ useCustomWorkingDirectory = "NO" ignoresPersistentStateOnLaunch = "NO" debugDocumentVersioning = "YES" - enableThreadSanitizer = "YES" debugServiceExtension = "internal" allowLocationSimulation = "YES"> diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 612c41d..f18ad4e 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -245,10 +245,10 @@ public protocol TaskEventType { var value: T? { get } /// Maps over the value embedded in a `Success` event. - func map( _ transform: @noescape(T) -> U) -> TaskEvent + func map(_ transform: @noescape(T) -> U) -> TaskEvent /// Convenience operator for mapping TaskEvents to SignalProducers. - func producerMap( _ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> + func producerMap(_ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> } /// Represents events that can occur during the execution of a task that is @@ -276,7 +276,7 @@ public enum TaskEvent: TaskEventType { } /// Maps over the value embedded in a `Success` event. - public func map( _ transform: @noescape(T) -> U) -> TaskEvent { + public func map(_ transform: @noescape(T) -> U) -> TaskEvent { switch self { case let .launch(task): return .launch(task) @@ -293,7 +293,7 @@ public enum TaskEvent: TaskEventType { } /// Convenience operator for mapping TaskEvents to SignalProducers. - public func producerMap( _ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> { + public func producerMap(_ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> { switch self { case let .launch(task): return .init(value: .launch(task)) @@ -332,7 +332,7 @@ public func == (lhs: TaskEvent, rhs: TaskEvent) -> Bool { extension TaskEvent: CustomStringConvertible { public var description: String { func dataDescription(_ data: Data) -> String { - return String(data: data, encoding: String.Encoding.utf8) ?? data.description + return String(data: data, encoding: .utf8) ?? data.description } switch self { @@ -494,7 +494,7 @@ public func launchTask(_ task: Task, standardInput: SignalProducer SignalProducer, TaskError> in - let errorString = (data.count > 0 ? NSString(data: data, encoding: String.Encoding.utf8.rawValue) as? String : nil) + let errorString = (data.count > 0 ? String(data: data, encoding: .utf8) : nil) return SignalProducer(error: .shellTaskFailed(task, exitCode: terminationStatus, standardError: errorString)) } .start(observer) diff --git a/ReactiveTaskTests/TaskSpec.swift b/ReactiveTaskTests/TaskSpec.swift index 66f95c2..262d842 100644 --- a/ReactiveTaskTests/TaskSpec.swift +++ b/ReactiveTaskTests/TaskSpec.swift @@ -46,7 +46,7 @@ class TaskSpec: QuickSpec { expect(result).notTo(beNil()) if let data = result?.value { - expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("foobar\n")) + expect(String(data: data, encoding: .utf8)).to(equal("foobar\n")) } } @@ -64,13 +64,13 @@ class TaskSpec: QuickSpec { expect(result).notTo(beNil()) if let data = result?.value { - expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("stat: not-a-real-file: stat: No such file or directory\n")) + expect(String(data: data, encoding: .utf8)).to(equal("stat: not-a-real-file: stat: No such file or directory\n")) } } it("should launch a task with standard input") { let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ] - let data = strings.map { $0.data(using: String.Encoding.utf8)! } + let data = strings.map { $0.data(using: .utf8)! } let result = launchTask(Task("/usr/bin/sort"), standardInput: SignalProducer(values: data)) .map { event in event.value } @@ -79,7 +79,7 @@ class TaskSpec: QuickSpec { expect(result).notTo(beNil()) if let data = result?.value { - expect(String(data: data, encoding: String.Encoding.utf8)).to(equal("bar\nbuzz\nfoo\nfuzz\n")) + expect(String(data: data, encoding: .utf8)).to(equal("bar\nbuzz\nfoo\nfuzz\n")) } } From 2d5131614fc33ea157c9d9bf3bd93d09b667bce8 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 4 Jul 2016 22:56:54 +1000 Subject: [PATCH 09/23] Track new ReactiveCocoa Swift 3 development branch. --- Cartfile | 2 +- Cartfile.resolved | 2 +- ReactiveTask/Task.swift | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cartfile b/Cartfile index 87745f3..29afa5b 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "RAC5-swift3" +github "ReactiveCocoa/ReactiveCocoa" "swift3.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index 158b2d1..60b6ea8 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -2,4 +2,4 @@ github "norio-nomura/Nimble" "fd248426eb8692b4616c2b842fcb9a2579b964e8" github "norio-nomura/Quick" "d3980a8bbafb13a973cb3018490e6577ee8307fd" github "liscio/Result" "e96316e6afabd5e1f1389571babc3cfee5edb5b9" github "jspahrsummers/xcconfigs" "0.9" -github "ReactiveCocoa/ReactiveCocoa" "538cec3cf7b2f2efeff2e559ee5bc2eb4d033989" +github "ReactiveCocoa/ReactiveCocoa" "ae09d9592fa55ad860806857499b44bd631c583e" diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index f18ad4e..f45823c 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -178,7 +178,7 @@ private final class Pipe { } } - let _ = disposable.addDisposable { + let _ = disposable.add { channel.close(flags: .stop) } } @@ -209,7 +209,7 @@ private final class Pipe { } producer.startWithSignal { signal, producerDisposable in - disposable.addDisposable(producerDisposable) + disposable.add(producerDisposable) signal.observe(Observer(next: { data in let bytes = UnsafeMutablePointer(allocatingCapacity: data.count) @@ -230,7 +230,7 @@ private final class Pipe { })) } - let _ = disposable.addDisposable { + let _ = disposable.add { channel.close(flags: .stop) } } @@ -511,13 +511,13 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Date: Tue, 5 Jul 2016 13:28:01 +1000 Subject: [PATCH 10/23] The "should launch a task with standard input" test now passes. --- ReactiveTask/Task.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index f45823c..557af7c 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -215,7 +215,7 @@ private final class Pipe { let bytes = UnsafeMutablePointer(allocatingCapacity: data.count) data.copyBytes(to: bytes, count: data.count) let buffer = UnsafeBufferPointer(start: bytes, count: data.count) - let dispatchData = DispatchData(bytes: buffer) + let dispatchData = DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {})) channel.write(offset: 0, data: dispatchData, queue: self.queue) { (done, data, error) in if error == ECANCELED { observer.sendInterrupted() From e81cd5c84103029525eaa21471ac72cf25b6a59f Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Tue, 5 Jul 2016 13:29:27 +1000 Subject: [PATCH 11/23] Make Travis CI use Xcode 8. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 21bc398..9e9db2a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: objective-c -osx_image: xcode7.3 +osx_image: xcode8 xcode_workspace: ReactiveTask.xcworkspace xcode_scheme: ReactiveTask script: script/cibuild From c341ba92a532f64410a5587dc0b27f75b29cf617 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Tue, 12 Jul 2016 16:12:58 +1000 Subject: [PATCH 12/23] Updated ReactiveCocoa. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.resolved | 8 ++++---- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/Quick | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- ReactiveTask/Task.swift | 8 ++++---- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitmodules b/.gitmodules index ccb593e..4580011 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/norio-nomura/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result - url = https://github.com/liscio/Result.git + url = https://github.com/antitypical/Result.git [submodule "Carthage/Checkouts/xcconfigs"] path = Carthage/Checkouts/xcconfigs url = https://github.com/jspahrsummers/xcconfigs.git diff --git a/Cartfile b/Cartfile index 29afa5b..167b0e0 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "swift3.0" +github "ReactiveCocoa/ReactiveCocoa" "RAC5" diff --git a/Cartfile.resolved b/Cartfile.resolved index 60b6ea8..0073255 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "norio-nomura/Nimble" "fd248426eb8692b4616c2b842fcb9a2579b964e8" -github "norio-nomura/Quick" "d3980a8bbafb13a973cb3018490e6577ee8307fd" -github "liscio/Result" "e96316e6afabd5e1f1389571babc3cfee5edb5b9" +github "norio-nomura/Nimble" "b8cdd5364d6770410043fd9ea13c32ef2f4ccdc7" +github "norio-nomura/Quick" "a72c211aa79069de25d10103262acf4974ddf80c" +github "antitypical/Result" "7d9c3ac21f22aaece85d37a0fc55ebd1eddf4df4" github "jspahrsummers/xcconfigs" "0.9" -github "ReactiveCocoa/ReactiveCocoa" "ae09d9592fa55ad860806857499b44bd631c583e" +github "ReactiveCocoa/ReactiveCocoa" "c495401c16fe4c4d495563b5520feba0cf8d53f2" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index fd24842..b8cdd53 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit fd248426eb8692b4616c2b842fcb9a2579b964e8 +Subproject commit b8cdd5364d6770410043fd9ea13c32ef2f4ccdc7 diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick index d3980a8..a72c211 160000 --- a/Carthage/Checkouts/Quick +++ b/Carthage/Checkouts/Quick @@ -1 +1 @@ -Subproject commit d3980a8bbafb13a973cb3018490e6577ee8307fd +Subproject commit a72c211aa79069de25d10103262acf4974ddf80c diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index ae09d95..c495401 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit ae09d9592fa55ad860806857499b44bd631c583e +Subproject commit c495401c16fe4c4d495563b5520feba0cf8d53f2 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index e96316e..7d9c3ac 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit e96316e6afabd5e1f1389571babc3cfee5edb5b9 +Subproject commit 7d9c3ac21f22aaece85d37a0fc55ebd1eddf4df4 diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 557af7c..f533a86 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -125,9 +125,9 @@ private final class Pipe { class func create(_ queue: DispatchQueue, _ group: DispatchGroup) -> Result { var fildes: [Int32] = [ 0, 0 ] if pipe(&fildes) == 0 { - return .Success(self.init(readFD: fildes[0], writeFD: fildes[1], queue: queue, group: group)) + return .success(self.init(readFD: fildes[0], writeFD: fildes[1], queue: queue, group: group)) } else { - return .Failure(.posixError(errno)) + return .failure(.posixError(errno)) } } @@ -409,14 +409,14 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Date: Thu, 4 Aug 2016 12:08:03 +1000 Subject: [PATCH 13/23] Xcode 8 beta 4 changes. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.resolved | 4 ++-- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- Carthage/Checkouts/xcconfigs | 2 +- ReactiveTask.xcodeproj/project.pbxproj | 10 +++++++++- .../xcshareddata/xcschemes/ReactiveTask.xcscheme | 2 +- ReactiveTask/Errors.swift | 2 +- ReactiveTask/Task.swift | 6 +++--- 10 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4580011..acaaebe 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/norio-nomura/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result - url = https://github.com/antitypical/Result.git + url = https://github.com/jameshurst/Result.git [submodule "Carthage/Checkouts/xcconfigs"] path = Carthage/Checkouts/xcconfigs url = https://github.com/jspahrsummers/xcconfigs.git diff --git a/Cartfile b/Cartfile index b5d1f45..2f56e04 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "swift3-beta-3" +github "ReactiveCocoa/ReactiveCocoa" "swift3-beta-4" diff --git a/Cartfile.resolved b/Cartfile.resolved index aab42dc..39eeba6 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ github "norio-nomura/Nimble" "20bb2eaad01f9df2b29f35d90783ae81b89f86b2" github "norio-nomura/Quick" "594479916dc6f87af514e3d64635a1358f3ae904" -github "antitypical/Result" "8f1affd40bc2b10a15f56ff6cb7b00639e29cb35" +github "jameshurst/Result" "a285bbc03874cfdf000b7b905e428c491fd497cd" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "7af0f7abcab29dcbe24b107bde3b811af01f3a15" +github "ReactiveCocoa/ReactiveCocoa" "289bda84ccf6c95ca131bf01623c4d2003e089a1" diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 7af0f7a..289bda8 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 7af0f7abcab29dcbe24b107bde3b811af01f3a15 +Subproject commit 289bda84ccf6c95ca131bf01623c4d2003e089a1 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index 8f1affd..cdf310d 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit 8f1affd40bc2b10a15f56ff6cb7b00639e29cb35 +Subproject commit cdf310de1a1258fc2b3f20e02b85438ba11695da diff --git a/Carthage/Checkouts/xcconfigs b/Carthage/Checkouts/xcconfigs index 1ef9763..d78854b 160000 --- a/Carthage/Checkouts/xcconfigs +++ b/Carthage/Checkouts/xcconfigs @@ -1 +1 @@ -Subproject commit 1ef97639ffbe041da0b1392b2114fa19b922a7a1 +Subproject commit d78854b22b9567e7f30d748bdd4966c86bcc93a5 diff --git a/ReactiveTask.xcodeproj/project.pbxproj b/ReactiveTask.xcodeproj/project.pbxproj index d06d834..80267a1 100644 --- a/ReactiveTask.xcodeproj/project.pbxproj +++ b/ReactiveTask.xcodeproj/project.pbxproj @@ -269,7 +269,7 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0700; - LastUpgradeCheck = 0710; + LastUpgradeCheck = 0800; ORGANIZATIONNAME = Carthage; TargetAttributes = { D0BFEA571A2D1E5E00E23194 = { @@ -350,6 +350,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0BFEA781A2D1E7C00E23194 /* Debug.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; ENABLE_TESTABILITY = YES; GCC_NO_COMMON_BLOCKS = YES; @@ -366,6 +368,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0BFEA7A1A2D1E7C00E23194 /* Release.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -438,6 +442,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0BFEA7B1A2D1E7C00E23194 /* Test.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; @@ -481,6 +487,8 @@ isa = XCBuildConfiguration; baseConfigurationReference = D0BFEA791A2D1E7C00E23194 /* Profile.xcconfig */; buildSettings = { + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; MACOSX_DEPLOYMENT_TARGET = 10.10; diff --git a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme index 4fa3d93..e027fea 100644 --- a/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme +++ b/ReactiveTask.xcodeproj/xcshareddata/xcschemes/ReactiveTask.xcscheme @@ -1,6 +1,6 @@ (allocatingCapacity: dispatchData.count) + let bytes = UnsafeMutablePointer.allocate(capacity: dispatchData.count) dispatchData.copyBytes(to: bytes, count: dispatchData.count) let data = Data(bytes: bytes, count: dispatchData.count) observer.sendNext(data) @@ -222,7 +222,7 @@ private final class Pipe { disposable.add(producerDisposable) signal.observe(Observer(next: { data in - let bytes = UnsafeMutablePointer(allocatingCapacity: data.count) + let bytes = UnsafeMutablePointer.allocate(capacity: data.count) data.copyBytes(to: bytes, count: data.count) let buffer = UnsafeBufferPointer(start: bytes, count: data.count) let dispatchData = DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {})) @@ -399,7 +399,7 @@ extension Signal where Value: TaskEventType { /// `TaskEvent`s as execution proceeds. public func launchTask(_ task: Task, standardInput: SignalProducer? = nil) -> SignalProducer, TaskError> { return SignalProducer { observer, disposable in - let queue = DispatchQueue(label: task.description, attributes: .serial) + let queue = DispatchQueue(label: task.description, attributes: []) let group = Task.group let rawTask = Foundation.Task() From 585cbdd59c74ddb89e324ec345c68c38d6db14d4 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Fri, 5 Aug 2016 12:09:19 +1000 Subject: [PATCH 14/23] Tracking ReactiveCocoa changes. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.private | 2 +- Cartfile.resolved | 8 ++++---- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/Quick | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- Carthage/Checkouts/xcconfigs | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.gitmodules b/.gitmodules index acaaebe..f0dfc4c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "Carthage/Checkouts/Nimble"] path = Carthage/Checkouts/Nimble - url = https://github.com/norio-nomura/Nimble.git + url = https://github.com/andersio/Nimble.git [submodule "Carthage/Checkouts/Quick"] path = Carthage/Checkouts/Quick url = https://github.com/norio-nomura/Quick.git diff --git a/Cartfile b/Cartfile index 2f56e04..167b0e0 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "swift3-beta-4" +github "ReactiveCocoa/ReactiveCocoa" "RAC5" diff --git a/Cartfile.private b/Cartfile.private index 039260b..8a06897 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ github "norio-nomura/Quick" "nn-swift-3-compatibility" -github "norio-nomura/Nimble" "nn-swift-3-compatibility" +github "andersio/Nimble" "swift3-beta-4" github "jspahrsummers/xcconfigs" "1ef9763" diff --git a/Cartfile.resolved b/Cartfile.resolved index 39eeba6..9f1d0ff 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "norio-nomura/Nimble" "20bb2eaad01f9df2b29f35d90783ae81b89f86b2" -github "norio-nomura/Quick" "594479916dc6f87af514e3d64635a1358f3ae904" -github "jameshurst/Result" "a285bbc03874cfdf000b7b905e428c491fd497cd" +github "andersio/Nimble" "7c0762319cd5c902a85b92722a0659cc33cd6338" +github "norio-nomura/Quick" "eaf60d980d88ffefd8c3a7515f53547453d5938b" +github "jameshurst/Result" "2401fa7584183da17f40335816073bf511fb34b8" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "289bda84ccf6c95ca131bf01623c4d2003e089a1" +github "ReactiveCocoa/ReactiveCocoa" "b4d757433574f85519bb3253a631955da937106a" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 20bb2ea..7c07623 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 20bb2eaad01f9df2b29f35d90783ae81b89f86b2 +Subproject commit 7c0762319cd5c902a85b92722a0659cc33cd6338 diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick index 5944799..eaf60d9 160000 --- a/Carthage/Checkouts/Quick +++ b/Carthage/Checkouts/Quick @@ -1 +1 @@ -Subproject commit 594479916dc6f87af514e3d64635a1358f3ae904 +Subproject commit eaf60d980d88ffefd8c3a7515f53547453d5938b diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 289bda8..b4d7574 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 289bda84ccf6c95ca131bf01623c4d2003e089a1 +Subproject commit b4d757433574f85519bb3253a631955da937106a diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index cdf310d..2401fa7 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit cdf310de1a1258fc2b3f20e02b85438ba11695da +Subproject commit 2401fa7584183da17f40335816073bf511fb34b8 diff --git a/Carthage/Checkouts/xcconfigs b/Carthage/Checkouts/xcconfigs index d78854b..1ef9763 160000 --- a/Carthage/Checkouts/xcconfigs +++ b/Carthage/Checkouts/xcconfigs @@ -1 +1 @@ -Subproject commit d78854b22b9567e7f30d748bdd4966c86bcc93a5 +Subproject commit 1ef97639ffbe041da0b1392b2114fa19b922a7a1 From e15a1c40e81a99e88a280b5084741a2bcbedf89a Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 8 Aug 2016 13:11:27 +1000 Subject: [PATCH 15/23] Update dependencies. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.resolved | 4 ++-- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.gitmodules b/.gitmodules index f0dfc4c..a1b8ddf 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,7 +6,7 @@ url = https://github.com/norio-nomura/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result - url = https://github.com/jameshurst/Result.git + url = https://github.com/antitypical/Result.git [submodule "Carthage/Checkouts/xcconfigs"] path = Carthage/Checkouts/xcconfigs url = https://github.com/jspahrsummers/xcconfigs.git diff --git a/Cartfile b/Cartfile index 167b0e0..38f3bb3 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "RAC5" +github "ReactiveCocoa/ReactiveCocoa" "master" diff --git a/Cartfile.resolved b/Cartfile.resolved index 9f1d0ff..cb8d9bb 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ github "andersio/Nimble" "7c0762319cd5c902a85b92722a0659cc33cd6338" github "norio-nomura/Quick" "eaf60d980d88ffefd8c3a7515f53547453d5938b" -github "jameshurst/Result" "2401fa7584183da17f40335816073bf511fb34b8" +github "antitypical/Result" "3.0.0-alpha.2" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "b4d757433574f85519bb3253a631955da937106a" +github "ReactiveCocoa/ReactiveCocoa" "d98489ae97b020ccdd9a8c8ccad2b67429817669" diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index b4d7574..d98489a 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit b4d757433574f85519bb3253a631955da937106a +Subproject commit d98489ae97b020ccdd9a8c8ccad2b67429817669 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index 2401fa7..03eb2c2 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit 2401fa7584183da17f40335816073bf511fb34b8 +Subproject commit 03eb2c274eb3cab2b2bd4b25586b3d6325607e2c From e373dae8c1f4082df66a973603207eb487bd7e86 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 8 Aug 2016 13:25:22 +1000 Subject: [PATCH 16/23] Set deployment target back to 10.9. Replace manual pointer creation with NSData.withUnsafeBytes. Remove Xcode 7 build from .travis.yml. --- .travis.yml | 3 --- ReactiveTask.xcodeproj/project.pbxproj | 8 ++++---- ReactiveTask/Task.swift | 9 +++++---- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 0377b92..c58b8a9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,9 +8,6 @@ script: - set -o pipefail && xcodebuild -workspace "$TRAVIS_XCODE_WORKSPACE" -scheme "$TRAVIS_XCODE_SCHEME" test | xcpretty matrix: include: - - osx_image: xcode7.3 - xcode_scheme: ReactiveTask - env: JOB=Xcode7.3 - osx_image: xcode8 xcode_scheme: ReactiveTask env: JOB=Xcode8 diff --git a/ReactiveTask.xcodeproj/project.pbxproj b/ReactiveTask.xcodeproj/project.pbxproj index 80267a1..d5d8ad8 100644 --- a/ReactiveTask.xcodeproj/project.pbxproj +++ b/ReactiveTask.xcodeproj/project.pbxproj @@ -355,7 +355,7 @@ CURRENT_PROJECT_VERSION = 1; ENABLE_TESTABILITY = YES; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; ONLY_ACTIVE_ARCH = YES; SDKROOT = macosx; SWIFT_VERSION = 2.3; @@ -372,7 +372,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; SWIFT_VERSION = 2.3; VERSIONING_SYSTEM = "apple-generic"; @@ -446,7 +446,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; SWIFT_VERSION = 2.3; VERSIONING_SYSTEM = "apple-generic"; @@ -491,7 +491,7 @@ CLANG_WARN_SUSPICIOUS_MOVE = YES; CURRENT_PROJECT_VERSION = 1; GCC_NO_COMMON_BLOCKS = YES; - MACOSX_DEPLOYMENT_TARGET = 10.10; + MACOSX_DEPLOYMENT_TARGET = 10.9; SDKROOT = macosx; SWIFT_VERSION = 2.3; VERSIONING_SYSTEM = "apple-generic"; diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 4f3e23d..976ce04 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -222,10 +222,11 @@ private final class Pipe { disposable.add(producerDisposable) signal.observe(Observer(next: { data in - let bytes = UnsafeMutablePointer.allocate(capacity: data.count) - data.copyBytes(to: bytes, count: data.count) - let buffer = UnsafeBufferPointer(start: bytes, count: data.count) - let dispatchData = DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {})) + let dispatchData = data.withUnsafeBytes { (bytes: UnsafePointer) -> DispatchData in + let buffer = UnsafeBufferPointer(start: bytes, count: data.count) + return DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {})) + } + channel.write(offset: 0, data: dispatchData, queue: self.queue) { (done, data, error) in if error == ECANCELED { observer.sendInterrupted() From d31b40bf7ac807198d19f2c796db13bb3c90457f Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Fri, 12 Aug 2016 12:43:40 +1000 Subject: [PATCH 17/23] Update ReactiveCocoa. Handle recent API changes in ReactiveCocoa. --- Cartfile.resolved | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- ReactiveTask/Task.swift | 17 +++++++++++++++-- ReactiveTaskTests/TaskSpec.swift | 2 +- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Cartfile.resolved b/Cartfile.resolved index cb8d9bb..1ce015f 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -2,4 +2,4 @@ github "andersio/Nimble" "7c0762319cd5c902a85b92722a0659cc33cd6338" github "norio-nomura/Quick" "eaf60d980d88ffefd8c3a7515f53547453d5938b" github "antitypical/Result" "3.0.0-alpha.2" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "d98489ae97b020ccdd9a8c8ccad2b67429817669" +github "ReactiveCocoa/ReactiveCocoa" "5d97c0509992f72a3cfe24a5b9ed74326325c0bc" diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index d98489a..5d97c05 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit d98489ae97b020ccdd9a8c8ccad2b67429817669 +Subproject commit 5d97c0509992f72a3cfe24a5b9ed74326325c0bc diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 976ce04..d33a2bd 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -56,6 +56,14 @@ private extension String { } } +//private extension Data { +// init(dispatchData: DispatchData) { +// self = dispatchData.withUnsafeBytes { bytes in +// return Data(bytes: bytes, count: dispatchData.count) +// } +// } +//} + extension Task: CustomStringConvertible { public var description: String { return "\(launchPath) \(arguments.map { $0.escaped }.joined(separator: " "))" @@ -171,9 +179,14 @@ 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 data = dispatchData.withUnsafeBytes { bytes in +// return Data(bytes: bytes, count: dispatchData.count) +// } + let bytes = UnsafeMutablePointer.allocate(capacity: dispatchData.count) dispatchData.copyBytes(to: bytes, count: dispatchData.count) let data = Data(bytes: bytes, count: dispatchData.count) + observer.sendNext(data) } @@ -385,7 +398,7 @@ extension Signal where Value: TaskEventType { .map { event in return event.value } - .ignoreNil() + .skipNil() } } @@ -478,7 +491,7 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Date: Thu, 18 Aug 2016 15:57:52 -0700 Subject: [PATCH 18/23] Changes for Xcode 8 beta 6 compatibility. Tests currently don't run; waiting for a beta 6 compatible version of Quick. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.private | 2 +- Cartfile.resolved | 6 +++--- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- ReactiveTask/Task.swift | 36 ++++++++++++++++---------------- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/.gitmodules b/.gitmodules index a1b8ddf..aefa764 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,6 @@ [submodule "Carthage/Checkouts/Nimble"] path = Carthage/Checkouts/Nimble - url = https://github.com/andersio/Nimble.git + url = https://github.com/ikesyo/Nimble.git [submodule "Carthage/Checkouts/Quick"] path = Carthage/Checkouts/Quick url = https://github.com/norio-nomura/Quick.git diff --git a/Cartfile b/Cartfile index 38f3bb3..d573cf1 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "master" +github "ReactiveCocoa/ReactiveCocoa" "swift3-beta-6" diff --git a/Cartfile.private b/Cartfile.private index 8a06897..f4b7971 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ github "norio-nomura/Quick" "nn-swift-3-compatibility" -github "andersio/Nimble" "swift3-beta-4" +github "ikesyo/Nimble" "swift3-beta-6" github "jspahrsummers/xcconfigs" "1ef9763" diff --git a/Cartfile.resolved b/Cartfile.resolved index 1ce015f..5d3251d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "andersio/Nimble" "7c0762319cd5c902a85b92722a0659cc33cd6338" +github "ikesyo/Nimble" "4caecb3cef0c9a2973c598b99e1495009faf57b1" github "norio-nomura/Quick" "eaf60d980d88ffefd8c3a7515f53547453d5938b" -github "antitypical/Result" "3.0.0-alpha.2" +github "antitypical/Result" "3.0.0-alpha.3" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "5d97c0509992f72a3cfe24a5b9ed74326325c0bc" +github "ReactiveCocoa/ReactiveCocoa" "736b1d8957b875f66f235f8e8defa9f793771e5a" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 7c07623..4caecb3 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 7c0762319cd5c902a85b92722a0659cc33cd6338 +Subproject commit 4caecb3cef0c9a2973c598b99e1495009faf57b1 diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 5d97c05..736b1d8 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 5d97c0509992f72a3cfe24a5b9ed74326325c0bc +Subproject commit 736b1d8957b875f66f235f8e8defa9f793771e5a diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index 03eb2c2..d78cac3 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit 03eb2c274eb3cab2b2bd4b25586b3d6325607e2c +Subproject commit d78cac38657de99d85f8f1770b290d039721ef27 diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index d33a2bd..259a5e9 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -38,7 +38,7 @@ public struct Task { } /// A GCD group which to wait completion - private static let group = DispatchGroup() + fileprivate static let group = DispatchGroup() /// wait for all task termination public static func waitForAllTaskTermination() { @@ -269,10 +269,10 @@ public protocol TaskEventType { var value: T? { get } /// Maps over the value embedded in a `Success` event. - func map(_ transform: @noescape(T) -> U) -> TaskEvent + func map(_ transform: (T) -> U) -> TaskEvent /// Convenience operator for mapping TaskEvents to SignalProducers. - func producerMap(_ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> + func producerMap(_ transform: (T) -> SignalProducer) -> SignalProducer, Error> } /// Represents events that can occur during the execution of a task that is @@ -300,7 +300,7 @@ public enum TaskEvent: TaskEventType { } /// Maps over the value embedded in a `Success` event. - public func map(_ transform: @noescape(T) -> U) -> TaskEvent { + public func map(_ transform: (T) -> U) -> TaskEvent { switch self { case let .launch(task): return .launch(task) @@ -317,7 +317,7 @@ public enum TaskEvent: TaskEventType { } /// Convenience operator for mapping TaskEvents to SignalProducers. - public func producerMap(_ transform: @noescape(T) -> SignalProducer) -> SignalProducer, Error> { + public func producerMap(_ transform: (T) -> SignalProducer) -> SignalProducer, Error> { switch self { case let .launch(task): return .init(value: .launch(task)) @@ -377,7 +377,7 @@ extension TaskEvent: CustomStringConvertible { extension SignalProducer where Value: TaskEventType { /// Maps the values inside a stream of TaskEvents into new SignalProducers. - public func flatMapTaskEvents(_ strategy: FlattenStrategy, transform: (Value.T) -> SignalProducer) -> SignalProducer, Error> { + public func flatMapTaskEvents(_ strategy: FlattenStrategy, transform: @escaping (Value.T) -> SignalProducer) -> SignalProducer, Error> { return self.flatMap(strategy) { taskEvent in return taskEvent.producerMap(transform) } @@ -416,16 +416,16 @@ public func launchTask(_ task: Task, standardInput: SignalProducer = .empty @@ -433,7 +433,7 @@ public func launchTask(_ task: Task, standardInput: SignalProducer TaskEvent) -> Pipe.ReadProducer { + func startAggregating(producer: Pipe.ReadProducer, chunk: @escaping (Data) -> TaskEvent) -> Pipe.ReadProducer { let aggregated = MutableProperty(nil) producer.startWithSignal { signal, signalDisposable in @@ -498,11 +498,11 @@ public func launchTask(_ task: Task, standardInput: SignalProducer Date: Tue, 23 Aug 2016 12:31:40 -0700 Subject: [PATCH 19/23] Update dependencies. Tests now run again. --- .gitmodules | 2 +- Cartfile | 2 +- Cartfile.private | 2 +- Cartfile.resolved | 6 +++--- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/Quick | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitmodules b/.gitmodules index aefa764..7617573 100644 --- a/.gitmodules +++ b/.gitmodules @@ -3,7 +3,7 @@ url = https://github.com/ikesyo/Nimble.git [submodule "Carthage/Checkouts/Quick"] path = Carthage/Checkouts/Quick - url = https://github.com/norio-nomura/Quick.git + url = https://github.com/ikesyo/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result url = https://github.com/antitypical/Result.git diff --git a/Cartfile b/Cartfile index d573cf1..38f3bb3 100644 --- a/Cartfile +++ b/Cartfile @@ -1 +1 @@ -github "ReactiveCocoa/ReactiveCocoa" "swift3-beta-6" +github "ReactiveCocoa/ReactiveCocoa" "master" diff --git a/Cartfile.private b/Cartfile.private index f4b7971..51dc361 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ -github "norio-nomura/Quick" "nn-swift-3-compatibility" +github "ikesyo/Quick" "xcode8-beta6" github "ikesyo/Nimble" "swift3-beta-6" github "jspahrsummers/xcconfigs" "1ef9763" diff --git a/Cartfile.resolved b/Cartfile.resolved index 5d3251d..1106a1d 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "ikesyo/Nimble" "4caecb3cef0c9a2973c598b99e1495009faf57b1" -github "norio-nomura/Quick" "eaf60d980d88ffefd8c3a7515f53547453d5938b" +github "ikesyo/Nimble" "4f38620db52b81eef4298492fed057247308b5d6" +github "ikesyo/Quick" "e14bf151a4c864e6f144559e7b7c09bca0fd38c1" github "antitypical/Result" "3.0.0-alpha.3" github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "736b1d8957b875f66f235f8e8defa9f793771e5a" +github "ReactiveCocoa/ReactiveCocoa" "b711611ad9906b1bfc5027824f57a2889e34204d" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 4caecb3..4f38620 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 4caecb3cef0c9a2973c598b99e1495009faf57b1 +Subproject commit 4f38620db52b81eef4298492fed057247308b5d6 diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick index eaf60d9..e14bf15 160000 --- a/Carthage/Checkouts/Quick +++ b/Carthage/Checkouts/Quick @@ -1 +1 @@ -Subproject commit eaf60d980d88ffefd8c3a7515f53547453d5938b +Subproject commit e14bf151a4c864e6f144559e7b7c09bca0fd38c1 diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index 736b1d8..b711611 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit 736b1d8957b875f66f235f8e8defa9f793771e5a +Subproject commit b711611ad9906b1bfc5027824f57a2889e34204d From 1d27a952fde3b9a4d630fdf029c421f97b4da54b Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Tue, 23 Aug 2016 12:37:20 -0700 Subject: [PATCH 20/23] Replace use of DispatchData(bytesNoCopy:deallocator:) with DispatchData(bytes:). This no longer causes a crash as of Xcode 8 beta 6. --- ReactiveTask/Task.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 259a5e9..28cb2f1 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -237,7 +237,7 @@ private final class Pipe { signal.observe(Observer(next: { data in let dispatchData = data.withUnsafeBytes { (bytes: UnsafePointer) -> DispatchData in let buffer = UnsafeBufferPointer(start: bytes, count: data.count) - return DispatchData(bytesNoCopy: buffer, deallocator: .custom(nil, {})) + return DispatchData(bytes: buffer) } channel.write(offset: 0, data: dispatchData, queue: self.queue) { (done, data, error) in From 5643f8cf212ae6608dac239acf3d0a29b6391d2b Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Thu, 8 Sep 2016 16:38:31 +1000 Subject: [PATCH 21/23] Update dependencies for Xcode 8 GM compatibility. --- .gitmodules | 4 ++-- Cartfile.private | 6 +++--- Cartfile.resolved | 10 +++++----- Carthage/Checkouts/Nimble | 2 +- Carthage/Checkouts/Quick | 2 +- Carthage/Checkouts/ReactiveCocoa | 2 +- Carthage/Checkouts/Result | 2 +- Carthage/Checkouts/xcconfigs | 2 +- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/.gitmodules b/.gitmodules index 7617573..0e96c9a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,9 @@ [submodule "Carthage/Checkouts/Nimble"] path = Carthage/Checkouts/Nimble - url = https://github.com/ikesyo/Nimble.git + url = https://github.com/Quick/Nimble.git [submodule "Carthage/Checkouts/Quick"] path = Carthage/Checkouts/Quick - url = https://github.com/ikesyo/Quick.git + url = https://github.com/Quick/Quick.git [submodule "Carthage/Checkouts/Result"] path = Carthage/Checkouts/Result url = https://github.com/antitypical/Result.git diff --git a/Cartfile.private b/Cartfile.private index 51dc361..6c9286a 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1,3 +1,3 @@ -github "ikesyo/Quick" "xcode8-beta6" -github "ikesyo/Nimble" "swift3-beta-6" -github "jspahrsummers/xcconfigs" "1ef9763" +github "jspahrsummers/xcconfigs" "3d9d996" +github "Quick/Quick" "swift-3.0" +github "Quick/Nimble" "swift-3.0" diff --git a/Cartfile.resolved b/Cartfile.resolved index 1106a1d..3f630f0 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,5 +1,5 @@ -github "ikesyo/Nimble" "4f38620db52b81eef4298492fed057247308b5d6" -github "ikesyo/Quick" "e14bf151a4c864e6f144559e7b7c09bca0fd38c1" -github "antitypical/Result" "3.0.0-alpha.3" -github "jspahrsummers/xcconfigs" "1ef97639ffbe041da0b1392b2114fa19b922a7a1" -github "ReactiveCocoa/ReactiveCocoa" "b711611ad9906b1bfc5027824f57a2889e34204d" +github "Quick/Nimble" "220152be528dcc0537764c179c95b8174028c80c" +github "Quick/Quick" "81d2a7bd95ef91e2604ee0431bba6fe59ad662dc" +github "antitypical/Result" "3.0.0-alpha.4" +github "jspahrsummers/xcconfigs" "3d9d99634cae6d586e272543d527681283b33eb0" +github "ReactiveCocoa/ReactiveCocoa" "a135a1f755c5e4435634a5432a0b622eb323f5d7" diff --git a/Carthage/Checkouts/Nimble b/Carthage/Checkouts/Nimble index 4f38620..220152b 160000 --- a/Carthage/Checkouts/Nimble +++ b/Carthage/Checkouts/Nimble @@ -1 +1 @@ -Subproject commit 4f38620db52b81eef4298492fed057247308b5d6 +Subproject commit 220152be528dcc0537764c179c95b8174028c80c diff --git a/Carthage/Checkouts/Quick b/Carthage/Checkouts/Quick index e14bf15..81d2a7b 160000 --- a/Carthage/Checkouts/Quick +++ b/Carthage/Checkouts/Quick @@ -1 +1 @@ -Subproject commit e14bf151a4c864e6f144559e7b7c09bca0fd38c1 +Subproject commit 81d2a7bd95ef91e2604ee0431bba6fe59ad662dc diff --git a/Carthage/Checkouts/ReactiveCocoa b/Carthage/Checkouts/ReactiveCocoa index b711611..a135a1f 160000 --- a/Carthage/Checkouts/ReactiveCocoa +++ b/Carthage/Checkouts/ReactiveCocoa @@ -1 +1 @@ -Subproject commit b711611ad9906b1bfc5027824f57a2889e34204d +Subproject commit a135a1f755c5e4435634a5432a0b622eb323f5d7 diff --git a/Carthage/Checkouts/Result b/Carthage/Checkouts/Result index d78cac3..cc1699d 160000 --- a/Carthage/Checkouts/Result +++ b/Carthage/Checkouts/Result @@ -1 +1 @@ -Subproject commit d78cac38657de99d85f8f1770b290d039721ef27 +Subproject commit cc1699dbd812c71bee7c44c8cbd75497713bc279 diff --git a/Carthage/Checkouts/xcconfigs b/Carthage/Checkouts/xcconfigs index 1ef9763..3d9d996 160000 --- a/Carthage/Checkouts/xcconfigs +++ b/Carthage/Checkouts/xcconfigs @@ -1 +1 @@ -Subproject commit 1ef97639ffbe041da0b1392b2114fa19b922a7a1 +Subproject commit 3d9d99634cae6d586e272543d527681283b33eb0 From a04403926941cea856fe74554d165cddc74608f7 Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Fri, 9 Sep 2016 09:30:07 +1000 Subject: [PATCH 22/23] Update documentation for Swift 3. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7fd8ccd..cf2b0ae 100644 --- a/README.md +++ b/README.md @@ -3,13 +3,13 @@ ReactiveTask is a Swift framework for launching shell tasks (processes), built u ```swift let strings = [ "foo\n", "bar\n", "buzz\n", "fuzz\n" ] -let input = SignalProducer(values: strings.map { $0.dataUsingEncoding(NSUTF8StringEncoding)! }) +let input = SignalProducer(values: strings.map { $0.data(using: .utf8)! }) let task = Task("/usr/bin/sort") // Run the task, ignoring the output, and do something with the final result. let result: Result? = launchTask(task, standardInput: input) .ignoreTaskData() - .map { String(data: $0, encoding: NSUTF8StringEncoding) } + .map { String(data: $0, encoding: .utf8) } .ignoreNil() .single() print("Output of `\(task)`: \(result?.value ?? "")") @@ -17,21 +17,21 @@ print("Output of `\(task)`: \(result?.value ?? "")") // Start the task and print all the events, which includes all the output // that was received. launchTask(task, standardInput: input) - .flatMapTaskEvents(.Concat) { data in - return SignalProducer(value: String(data: data, encoding: NSUTF8StringEncoding)) + .flatMapTaskEvents(.concat) { data in + return SignalProducer(value: String(data: data, encoding: .utf8)) } .startWithNext { (event: TaskEvent) in switch event { - case let .Launch(task): + case let .launch(task): print("launched task: \(task)") - case let .StandardError(data): + case let .standardError(data): print("stderr: \(data)") - case let .StandardOutput(data): + case let .standardOutput(data): print("stdout: \(data)") - case let .Success(string): + case let .success(string): print("value: \(string ?? "")") } } From e597cb679ff7c3c4c10033bde1428fbcde1a9f0c Mon Sep 17 00:00:00 2001 From: Matt Prowse Date: Mon, 12 Sep 2016 13:59:06 +1000 Subject: [PATCH 23/23] Remove commented out code. Fix memory leak in use of UnsafeMutablePointer. --- ReactiveTask/Task.swift | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/ReactiveTask/Task.swift b/ReactiveTask/Task.swift index 28cb2f1..048675f 100644 --- a/ReactiveTask/Task.swift +++ b/ReactiveTask/Task.swift @@ -56,14 +56,6 @@ private extension String { } } -//private extension Data { -// init(dispatchData: DispatchData) { -// self = dispatchData.withUnsafeBytes { bytes in -// return Data(bytes: bytes, count: dispatchData.count) -// } -// } -//} - extension Task: CustomStringConvertible { public var description: String { return "\(launchPath) \(arguments.map { $0.escaped }.joined(separator: " "))" @@ -179,13 +171,11 @@ 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 data = dispatchData.withUnsafeBytes { bytes in -// return Data(bytes: bytes, count: dispatchData.count) -// } - 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) observer.sendNext(data) }