Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swift 3: Using URLComponents
//: # Swift 3: Using URLComponents
import Foundation
//: ### Compose the componens
var url = URLComponents()
url.scheme = "http"
url.host = "google.com"
//: ### Pass the query string parameters
url.queryItems = [
URLQueryItem(name: "test", value: "data"),
URLQueryItem(name: "foo", value: "bar")
]
//: ### Output the formatted URL
print(url.string!)
//: ### Output the formatted query string
print(url.query!)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment