0

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 ?

Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
0xChqrles
  • 433
  • 1
  • 5
  • 10

0 Answers0