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
Btn read 3c0e607615 iOS Developer Blog
Btn subscribe 930758687e Subscribe: Email · Twitter
Btn training bbbdf557d2 Next iOS training: 19. - 23. November 2018, Hamburg
Btn about 5378472193 About me · Contact