Browse Source

Fixed `substring` API warnings for Swift 3.2 and up (#2240)

* Fixed `substring` API warnings for Swift 3.2 and up

* Updated whitespace around #if checks
htinlinn 8 năm trước cách đây
mục cha
commit
e396a0efc1
3 tập tin đã thay đổi với 10 bổ sung2 xóa
  1. 2 2
      Source/ParameterEncoding.swift
  2. 4 0
      Source/Request.swift
  3. 4 0
      Source/Validation.swift

+ 2 - 2
Source/ParameterEncoding.swift

@@ -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
             }

+ 4 - 0
Source/Request.swift

@@ -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
             }
         }
 

+ 4 - 0
Source/Validation.swift

@@ -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: "/")
             }()