nazaniel nazaniel - 1 year ago 126
Swift Question

NSURL relativeToURL backwards?

My NSURLs are being formatted backwards, even when copying and pasting in code from other projects which makes zero sense.

For example:

let baseURL = NSURL(string: "")
NSURL(string: "foo", relativeToURL: baseURL)

Should return: ""

Instead returns: "foo -- ttp://"

Has anyone seen this before?

Answer Source

That's simply how relative URLs are displayed in their (debug) description. The absoluteString will still be correct; this format is unrelated.

let baseURL = NSURL(string: "")!
let u = NSURL(string: "foo", relativeToURL: baseURL)!

print(u)  // prints the URL's description, "foo --"
print(u.absoluteString)  // prints ""
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download