Skip to content

Instantly share code, notes, and snippets.

@sebasbad
Last active January 2, 2017 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sebasbad/de15d930d48a845e1b1a78ba1130116d to your computer and use it in GitHub Desktop.
Save sebasbad/de15d930d48a845e1b1a78ba1130116d to your computer and use it in GitHub Desktop.
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