所以这是我的代码:
let queryItems = [URLQueryItem(name: "foo", value: "bar")]
var urlComponents = URLComponents(string: "http://example.com/fiz")
urlComponents?.queryItems = queryItems
print(urlComponents?.url?.absoluteString)
打印的字符串是http://example.com/fiz
. 但是如果在打印之前放置一个断点并在调试器中输入:
expression urlComponents?.queryItems = queryItems
打印的字符串将是http://example.com/fiz?foo=bar
另外,如果我强制(如下所示)打开 urlComponent,它就可以工作
var urlComponents = URLComponents(string: "http://example.com/fiz")!
这是正常行为吗?