diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..5186d07 --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +4.0 diff --git a/Source/Argument.swift b/Source/Argument.swift index 59187c0..3253f38 100644 --- a/Source/Argument.swift +++ b/Source/Argument.swift @@ -91,6 +91,6 @@ extension String { let actualRange = (characters.index(startIndex, offsetBy: range.lowerBound) ..< characters.index(endIndex, offsetBy: -distanceFromEndIndex)) - return self[actualRange] + return String(self[actualRange]) } } diff --git a/Source/Ask.swift b/Source/Ask.swift index 4336624..83d3c3d 100644 --- a/Source/Ask.swift +++ b/Source/Ask.swift @@ -30,7 +30,7 @@ public func ask(_ prompt: String, customizationBlock: ((AskSettings) -> - returns: The string casted to the type requested - discussion: If the user enters a wrong type, ask will keep prompting until a correct value has been entered */ -public func ask(_ prompt: String, type: T.Type, customizationBlock: ((AskSettings) -> Void)? = nil) -> T { +public func ask(_ prompt: String, type: T.Type, customizationBlock: ((AskSettings) -> Void)? = nil) -> T { PromptSettings.print(prompt) diff --git a/Source/ChooseSettings.swift b/Source/ChooseSettings.swift index b033e78..93b77ec 100644 --- a/Source/ChooseSettings.swift +++ b/Source/ChooseSettings.swift @@ -24,7 +24,7 @@ public enum ChoiceIndexType { public class ChooseSettings { typealias Item = T - var choices: [(choice: String, callback: (Void) -> T)] = [] + var choices: [(choice: String, callback: () -> T)] = [] /// Prompt message to use public var promptQuestion = "" @@ -41,7 +41,7 @@ public class ChooseSettings { - parameter choice: Item name - parameter callback: callback called when the item is selected, the value returned from this call back will be returned from choose */ - public func addChoice(_ choice: String..., callback: @escaping (Void) -> T) { + public func addChoice(_ choice: String..., callback: @escaping () -> T) { choice.forEach { choices.append(($0, callback)) } @@ -85,14 +85,15 @@ public class ChooseSettings { } func preparePromptItems() -> [String] { - return zip(indexChoices(), stringChoices()).map { index, string in + return zip(indexChoices(), stringChoices()).map { pair in + let (index, string) = pair return "\(index)\(indexSuffix)\(string)" } } func indexChoices() -> [String] { - return stringChoices().enumerated().map { itemIndex, string in - + return stringChoices().enumerated().map { pair in + let (itemIndex, _) = pair if index == .numbers { return "\(itemIndex + 1)" } else { diff --git a/Source/Env.swift b/Source/Env.swift index c09189c..da33456 100644 --- a/Source/Env.swift +++ b/Source/Env.swift @@ -89,7 +89,10 @@ public class Env { - parameter callback: callback to call on each key/value pair */ public static func eachPair(_ callback: (_ key: String, _ value: String) -> ()) { - zip(self.keys, self.values).forEach(callback) + zip(self.keys, self.values).forEach { (pair) in + let (key, value) = pair + callback(key, value) + } } } diff --git a/Source/RunResults.swift b/Source/RunResults.swift index a3b0e87..d8c81c5 100644 --- a/Source/RunResults.swift +++ b/Source/RunResults.swift @@ -36,5 +36,5 @@ func splitCommandToArgs(_ command: String) -> [String] { func readPipe(_ pipe: TaskPipe) -> String { let data = pipe.read() - return NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue) as? String ?? "" + return NSString(data: data as Data, encoding: String.Encoding.utf8.rawValue) as String? ?? "" } diff --git a/Swiftline.xcodeproj/project.pbxproj b/Swiftline.xcodeproj/project.pbxproj index 618abca..34ea6ea 100644 --- a/Swiftline.xcodeproj/project.pbxproj +++ b/Swiftline.xcodeproj/project.pbxproj @@ -180,7 +180,7 @@ LastUpgradeCheck = 9999; TargetAttributes = { "______Target_Swiftline" = { - LastSwiftMigration = 0800; + LastSwiftMigration = 0900; }; }; }; @@ -252,7 +252,7 @@ PRODUCT_BUNDLE_IDENTIFIER = Swiftline; PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Release; }; @@ -269,7 +269,7 @@ PRODUCT_MODULE_NAME = "$(TARGET_NAME:c99extidentifier)"; PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 3.0; + SWIFT_VERSION = 4.0; }; name = Debug; };