Created
October 16, 2015 17:14
-
-
Save zef/5f021cf4ad68741d77f4 to your computer and use it in GitHub Desktop.
Swift NSURL extension to turn the query into a dictionary
This file contains 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 NSURL { | |
var queryDictionary: [String: String] { | |
guard let components = NSURLComponents(string: absoluteString), items = components.queryItems else { return [:] } | |
return items.reduce([:]) { dictionary, item in | |
var dictionary = dictionary | |
dictionary[item.name] = item.value | |
return dictionary | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment