Adding query parameter to the GET url in iOS in Swift3

Viewed 7113

I have an URL with

https://api.asiancar.com/api/applicationsettings

It is basically a GET url so I need to pass a boolean "isMobile" and timestamp as query parameters . How to achieve this as the ultimate URL after passing the query will look like this:

https://api.asiancar.com/api/applicationsettings?timestamp=111122244556789879&isMobile=true

let queryItems = [
    NSURLQueryItem(timestamp: "1234568878788998989", isMobile: true),
    NSURLQueryItem(timestamp: "1234568878788998989", isMobile: true)
]
let urlComps = NSURLComponents(string: "www.api.asiancar.com/api/applicationsettings")!
urlComps.queryItems = queryItems
let URL = urlComps.URL!

Am I doing right or any other modification ? please tell.

3 Answers
Related