I cannot make `URLComponents.init()` return nil.
How have you checked that the result was nil? Isn't that just the debugger's malfunctioning?
I have checked that the result is nil and if I let the simulater continue it will fail.
I have checked that the result is nil
Please explain how. You inserted `print`? Or you have checked any of the variables with debugger?
if I let the simulater continue it will fail.
That does not always mean `URLComponents` is nil.
If you really want to solve your issue, please show enough info to solve it.
The code you have shown finishes without any problems on my simulator of Xcode 11. (With dummy `api(path:data:)`.
You may not be showing the exact code which causes the issue, or there may be something wrong somewhere currently not shown.
OK, now it is working when I initialize urlComps and then initialize urlComps.path with the following two lines.
var urlComps: URLComponents = URLComponents()
urlComps.path = "/user/auser"
I printed it in the console using control click (Print Description of "urlComps") or mousing over urlComps in the source code and clicking the i icon shows the value for path. This is also the method I used when urlComps was showing nil.
Printing description of urlComps:
- path : "/user/auser"
It also works as
var urlComps = URLComponents()
It must have been my error but before posting the initial question, I tried these and many ways of creating the instance. They were all producing nil but are now working. Even as I was writing my response some failed that now work. I know code does not magically start working but unfortunately I didn't catch whatever I did to fix this.
Thank you for your response. I'll be sure to provide much greater detail with questions in the future.
It must have been my error
Possibly, but not necessarily. Xcode has some bugs when showing values of Swift types, all the method you have tried may show some false content. That's why I once suggested Isn't that just the debugger's malfunctioning? and insisted Please explain how.
I guess you had some bugs in other parts of your code, and the false info by the Xcode had made you confused, but accidentally you fixed it.
Just my guess. Next time (if any) I believe we can find the real reason.
Same as my problem.