Skip to content

Instantly share code, notes, and snippets.

@hashaam
Last active September 2, 2017 09:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Get Specific URLQueryItem from URLComponents
// 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