So here's my code:
let queryItems = [URLQueryItem(name: "foo", value: "bar")]
var urlComponents = URLComponents(string: "http://example.com/fiz")
urlComponents?.queryItems = queryItems
print(urlComponents?.url?.absoluteString)
The printed string is http://example.com/fiz
. But if a put a breakpoint before the print and type in debugger:
expression urlComponents?.queryItems = queryItems
The printed string will be http://example.com/fiz?foo=bar
Also, if I force (as bellow) the unwrap of the urlComponent, it's working
var urlComponents = URLComponents(string: "http://example.com/fiz")!
Is that a normal behaviour ?