Last active
January 2, 2017 23:23
-
-
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)
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
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