Skip to content

Instantly share code, notes, and snippets.

@stinger
Created June 21, 2016 11:03
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stinger/06d5260d63b4c887d560d61ade8e8a66 to your computer and use it in GitHub Desktop.
Save stinger/06d5260d63b4c887d560d61ade8e8a66 to your computer and use it in GitHub Desktop.
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