import Foundation /// A type which can be converted to an URL string. public protocol URLConvertible { var urlValue: URL? { get } var urlStringValue: String { get } /// Returns URL query parameters. For convenience, this property will never return `nil` even if /// there's no query string in the URL. This property doesn't take care of the duplicated keys. /// For checking duplicated keys, use `queryItems` instead. /// /// - seealso: `queryItems` var queryParameters: [String: String] { get } /// Returns `queryItems` property of `URLComponents` instance. /// /// - seealso: `queryParameters` @available(iOS 8, *) var queryItems: [URLQueryItem]? { get } } extension URLConvertible { public var queryParameters: [String: String] { var parameters = [String: String]() self.urlValue?.query?.components(separatedBy: "&").forEach { component in guard let separatorIndex = component.firstIndex(of: "=") else { return } let keyRange = component.startIndex..