NSURL
NSURL also has the initializer NSURL(string:relativeToURL:), which can be used to construct a URL from a string relative to a base URL. The behavior of this method can be a source of confusion, because of how it treats leading /’s in relative paths.
NSURL is Foundation’s class for URLs. Create it with NSURL(string:), it returns nil if the string is invalid.
Use NSURL(string:relativeToURL:) for relative paths. A leading / makes it absolute to the base URL; without a leading /, it appends to the base path.
NSURL gives read-only properties: scheme, host, port, user, password, path, query, fragment, pathComponents, lastPathComponent, pathExtension, etc.
Use NSURL for immutable URLs, NSURLComponents when you need to build or modify URLs safely component-by-component, and bookmark URLs when you need a persistent reference to a file.
Category:
Tags:
Year: