Skip to content

Commit

Permalink
Fixed substring API warnings for Swift 3.2 and up (Alamofire#2240)
Browse files Browse the repository at this point in the history
* Fixed `substring` API warnings for Swift 3.2 and up

* Updated whitespace around #if checks
  • Loading branch information
htinlinn authored and jshier committed Aug 22, 2017
1 parent 0d2348d commit e396a0e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Source/ParameterEncoding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ public struct URLEncoding: ParameterEncoding {
let endIndex = string.index(index, offsetBy: batchSize, limitedBy: string.endIndex) ?? string.endIndex
let range = startIndex..<endIndex

let substring = string.substring(with: range)
let substring = string[range]

escaped += substring.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) ?? substring
escaped += substring.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet) ?? String(substring)

index = endIndex
}
Expand Down
4 changes: 4 additions & 0 deletions Source/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,11 @@ extension Request: CustomDebugStringConvertible {
let cookies = cookieStorage.cookies(for: url), !cookies.isEmpty
{
let string = cookies.reduce("") { $0 + "\($1.name)=\($1.value);" }
#if swift(>=3.2)
components.append("-b \"\(string[..<string.index(before: string.endIndex)])\"")
#else
components.append("-b \"\(string.substring(to: string.characters.index(before: string.endIndex)))\"")
#endif
}
}

Expand Down
4 changes: 4 additions & 0 deletions Source/Validation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ extension Request {
init?(_ string: String) {
let components: [String] = {
let stripped = string.trimmingCharacters(in: .whitespacesAndNewlines)
#if swift(>=3.2)
let split = stripped[..<(stripped.range(of: ";")?.lowerBound ?? stripped.endIndex)]
#else
let split = stripped.substring(to: stripped.range(of: ";")?.lowerBound ?? stripped.endIndex)
#endif
return split.components(separatedBy: "/")
}()

Expand Down

0 comments on commit e396a0e

Please sign in to comment.