Skip to content

Instantly share code, notes, and snippets.

@zef
Created October 16, 2015 17:14
Show Gist options
  • Save zef/5f021cf4ad68741d77f4 to your computer and use it in GitHub Desktop.
Save zef/5f021cf4ad68741d77f4 to your computer and use it in GitHub Desktop.
Swift NSURL extension to turn the query into a dictionary
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