February 13, 2017 · Ralf Ebert » iOS Developer Blog »

Encoding HTTP GET parameters

Use NSURLComponents to encode HTTP GET parameters:

Playground Icon

var urlComponents = URLComponents(string: "https://www.google.de/maps/")!
urlComponents.queryItems = [
    URLQueryItem(name: "q", value: String(51.500833)+","+String(-0.141944)),
    URLQueryItem(name: "z", value: String(6))
]
urlComponents.url      // returns https://www.google.de/maps/?q=51.500833,-0.141944&z=6
More... iOS Developer Blog
Subscribe Subscribe: Email · Twitter
iOS training Next iOS training: 25. Februar - 01. März 2019, Stuttgart
Contact About me · Contact