Last active
September 2, 2017 09:13
-
-
Save hashaam/77769e6e45ebc691edf66309720f0f35 to your computer and use it in GitHub Desktop.
Get Specific URLQueryItem from URLComponents
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
// https://hashaam.com/2017/09/02/get-specific-urlqueryitem-from-urlcomponents | |
func queryParam(urlString: String?, param: String) -> String? { | |
guard let urlString = urlString else { return nil } | |
guard let urlComponents = URLComponents(string: urlString) else { return nil } | |
guard let queryItems = urlComponents.queryItems else { return nil } | |
return queryItems.filter { queryItem in | |
return queryItem.name == param | |
}.first?.value | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment