I tested below code:
var c = URLComponents(string: "myscheme://")!
c.host = "my host with space"
let url = c.url!
print(url)
print(url.host)
In Xcode 13.4, the console prints:
myscheme://my%20host%20with%20space
Optional("my host with space")
In Xcode 14, the console prints:
myscheme:
nil
According to URLCompinents.host
documentation, it should encode in setter:
The getter for this property removes any percent encoding this component may have (if the component allows percent encoding). Setting this property assumes the subcomponent or component string is not percent encoded and will add percent encoding (if the component allows percent encoding).