Home > AI > IOS > Foundation >

NSURLComponents(url:resolvingAgainstBaseURL:)

Example:

let baseURL = NSURL(string: "http://server/foo/")!
let url = NSURL(string: "bar/file.html", relativeTo: baseURL as URL)!
print(url.absoluteString)
print(url.absoluteURL)
print(url.relativeString)
print(url.relativePath)
// "http://server/foo/bar/file.html"


// relative path
let comp1 = NSURLComponents(url: url as URL, resolvingAgainstBaseURL: false)!
print(comp1.string!)


// absolute path
let comp2 = NSURLComponents(url: url as URL, resolvingAgainstBaseURL: true)!
print(comp2.string!)

Leave a Reply