即使从其他项目复制和粘贴代码,我的 NSURL 也会向后格式化,这毫无意义。
例如:
let baseURL = NSURL(string: "http://example.com/v1/")
NSURL(string: "foo", relativeToURL: baseURL)
应返回:“http://example.com/v1/foo”
而是返回:“foo -- ttp://example.com/v1/”
有人见过这个吗?
最佳答案
这就是相对 URL 在其(调试)描述中的显示方式。 absoluteString
仍然是正确的;此格式无关。
let baseURL = NSURL(string: "http://example.com/v1/")!
let u = NSURL(string: "foo", relativeToURL: baseURL)!
print(u) // prints the URL's description, "foo -- http://example.com/v1/"
print(u.absoluteString) // prints "http://example.com/v1/foo"
关于swift - NSURLrelativeToURL 向后?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37066394/