Skip to content

Instantly share code, notes, and snippets.

@Andy0570
Created November 18, 2020 03:15
Show Gist options
  • Save Andy0570/15373d90cb47a4de1d3779024a47b0f6 to your computer and use it in GitHub Desktop.
Save Andy0570/15373d90cb47a4de1d3779024a47b0f6 to your computer and use it in GitHub Desktop.
import Foundation
extension URL {
func withQueries(_ queries: [String: String]) -> URL? {
var components = URLComponents(url: self, resolvingAgainstBaseURL: true)
components?.queryItems = queries.compactMap { URLQueryItem(name: $0.0, value: $0.1) }
return components?.url
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment