Created
June 13, 2017 05:28
-
-
Save sanjaymhj/fb99f67252e6281ceac0ec3a050e4d82 to your computer and use it in GitHub Desktop.
URL Extension to Create Query Parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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