Skip to content

Instantly share code, notes, and snippets.

@sanjaymhj
Created June 13, 2017 05:28
Show Gist options
  • Save sanjaymhj/fb99f67252e6281ceac0ec3a050e4d82 to your computer and use it in GitHub Desktop.
Save sanjaymhj/fb99f67252e6281ceac0ec3a050e4d82 to your computer and use it in GitHub Desktop.
URL Extension to Create Query Parameter
extension URL {
/*
Get the query parameters from the URL.
*/
var queryParameters: [String: String]? {
var params = [String: String]()
return URLComponents(url: self, resolvingAgainstBaseURL: false)?
.queryItems?
.reduce([:], { (_, item) -> [String: String] in
params[item.name] = item.value
return params
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment