Skip to content

Instantly share code, notes, and snippets.

@sebasbad
Last active Jan 2, 2017
Embed
What would you like to do?
URL swift extension to get query parameter values array (adapted from https://gist.github.com/InsertNetan/372c9f51549ea96e5af2)
import Foundation
extension URL {
func queryItemValues(key: String) -> [String?]? {
guard let components = NSURLComponents(url: self, resolvingAgainstBaseURL: false) else {
return nil
}
guard let queryItems = components.queryItems else { return nil }
return queryItems.filter {
$0.name == key
}.map {
$0.value
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment