Created
October 16, 2015 17:14
Swift NSURL extension to turn the query into a dictionary
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 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