diff --git a/Source/CarthageKit/BuildSettings.swift b/Source/CarthageKit/BuildSettings.swift index 8bd327f236..22efb417e2 100644 --- a/Source/CarthageKit/BuildSettings.swift +++ b/Source/CarthageKit/BuildSettings.swift @@ -89,11 +89,11 @@ public struct BuildSettings { return } - if let result = self.targetSettingsRegex.firstMatch(in: line, range: NSRange(location: 0, length: line.utf16.count)) { - let targetRange = result.range(at: 1) + if let result = self.targetSettingsRegex.firstMatch(in: line, range: NSRange(line.startIndex..., in: line)) { + let targetRange = Range(result.range(at: 1), in: line)! flushTarget() - currentTarget = (line as NSString).substring(with: targetRange) + currentTarget = line.substring(with: targetRange) return } diff --git a/Source/CarthageKit/GitHub.swift b/Source/CarthageKit/GitHub.swift index 90e75c7d8a..320a1c6446 100644 --- a/Source/CarthageKit/GitHub.swift +++ b/Source/CarthageKit/GitHub.swift @@ -39,10 +39,10 @@ extension Repository { /// Enterprise instances. public static func fromIdentifier(_ identifier: String) -> Result<(Server, Repository), ScannableError> { // ‘owner/name’ → GitHub.com - let range = NSRange(location: 0, length: identifier.utf16.count) + let range = NSRange(identifier.startIndex..., in: identifier) if let match = nwoRegex.firstMatch(in: identifier, range: range) { - let owner = (identifier as NSString).substring(with: match.range(at: 1)) - let name = (identifier as NSString).substring(with: match.range(at: 2)) + let owner = identifier.substring(with: Range(match.range(at: 1), in: identifier)!) + let name = identifier.substring(with: Range(match.range(at: 2), in: identifier)!) return .success((.dotCom, self.init(owner: owner, name: strippingGitSuffix(name)))) } diff --git a/Source/CarthageKit/Xcode.swift b/Source/CarthageKit/Xcode.swift index 5fd2144168..7e15ba5562 100644 --- a/Source/CarthageKit/Xcode.swift +++ b/Source/CarthageKit/Xcode.swift @@ -37,7 +37,7 @@ private func parseSwiftVersionCommand(output: String?) -> String? { guard let output = output, let regex = try? NSRegularExpression(pattern: "Apple Swift version ([0-9.]+) .*\\((.+)\\)", options: []), - let match = regex.firstMatch(in: output, options: [], range: NSRange(location: 0, length: output.characters.count)) + let match = regex.firstMatch(in: output, options: [], range: NSRange(output.startIndex..., in: output)) else { return nil @@ -45,8 +45,9 @@ private func parseSwiftVersionCommand(output: String?) -> String? { guard match.numberOfRanges == 3 else { return nil } - let nsString = output as NSString - return "\(nsString.substring(with: match.range(at: 1))) (\(nsString.substring(with: match.range(at: 2))))" + let first = output.substring(with: Range(match.range(at: 1), in: output)!) + let second = output.substring(with: Range(match.range(at: 2), in: output)!) + return "\(first) (\(second))" } /// Determines the Swift version of a framework at a given `URL`. @@ -581,10 +582,10 @@ private func build(sdk: SDK, with buildArgs: BuildArguments, in workingDirectory pattern: "-- \(platformName) [0-9.]+ --\\n.*?\\(([0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12})\\)", options: [] ) - let lastDeviceResult = regex.matches(in: string, range: NSRange(location: 0, length: string.utf16.count)).last + let lastDeviceResult = regex.matches(in: string, range: NSRange(string.startIndex..., in: string)).last return lastDeviceResult.map { result in // We use the ID here instead of the name as it's guaranteed to be unique, the name isn't. - let deviceID = (string as NSString).substring(with: result.range(at: 1)) + let deviceID = string.substring(with: Range(result.range(at: 1), in: string)!) return "platform=\(platformName) Simulator,id=\(deviceID)" } } diff --git a/Source/XCDBLD/XcodeVersion.swift b/Source/XCDBLD/XcodeVersion.swift index 6c30541d57..8b23714840 100644 --- a/Source/XCDBLD/XcodeVersion.swift +++ b/Source/XCDBLD/XcodeVersion.swift @@ -22,14 +22,13 @@ public struct XcodeVersion { } internal init?(xcodebuildOutput: String) { - let range = NSRange(location: 0, length: xcodebuildOutput.utf16.count) + let range = NSRange(xcodebuildOutput.startIndex..., in: xcodebuildOutput) guard let match = XcodeVersion.regex.firstMatch(in: xcodebuildOutput, range: range) else { return nil } - let nsString = xcodebuildOutput as NSString - let version = nsString.substring(with: match.range(at: 1)) - let buildVersion = nsString.substring(with: match.range(at: 2)) + let version = xcodebuildOutput.substring(with: Range(match.range(at: 1), in: xcodebuildOutput)!) + let buildVersion = xcodebuildOutput.substring(with: Range(match.range(at: 2), in: xcodebuildOutput)!) self.init(version: version, buildVersion: buildVersion) }