StructureFoundation5.9.0
URL
A URL is a type that can potentially contain the location of a resource on a remote server, the path of a local file on disk, or even an arbitrary piece of encoded data.
struct URL
You can construct URLs and access their parts. For URLs that represent local files, you can also manipulate properties of those files directly, such as changing the file’s last modification date. Finally, you can pass URLs to other APIs to retrieve the contents of those URLs. For example, you can use the URLSession classes to access the contents of remote resources, as described in URL Session Programming Guide.
URLs are the preferred way to refer to local files. Most objects that read data from or write data to a file have methods that accept a URL instead of a pathname as the file reference. For example, you can get the contents of a local file URL as String
by calling func init(contentsOf:encoding) throws
, or as a Data
by calling func init(contentsOf:options) throws
.
Citizens in Foundation
Conformances
protocol CustomDebugStringConvertible
A type with a customized textual representation suitable for debugging purposes.
protocol CustomPlaygroundDisplayConvertible
A type that supplies a custom description for playground logging.
protocol CustomStringConvertible
A type with a customized textual representation.
protocol Decodable
A type that can decode itself from an external representation.
protocol Encodable
A type that can encode itself to an external representation.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol ReferenceConvertible
Decorates types which are backed by a Foundation reference type.
Members
init?(dataRepresentation: Data, relativeTo: URL?, isAbsolute: Bool
) Initializes a newly created URL using the contents of the given data, relative to a base URL.
init(fileReferenceLiteralResourceName: String
) init(fileURLWithFileSystemRepresentation: UnsafePointer<Int8>, isDirectory: Bool, relativeTo: URL?
) Initializes a newly created URL referencing the local file or directory at the file system representation of the path. File system representation is a null-terminated C string with canonical UTF-8 encoding.
init(fileURLWithPath: String
) Initializes a newly created file URL referencing the local file or directory at path.
init(fileURLWithPath: String, isDirectory: Bool
) Initializes a newly created file URL referencing the local file or directory at path.
init(fileURLWithPath: String, isDirectory: Bool, relativeTo: URL?
) Initializes a newly created file URL referencing the local file or directory at path, relative to a base URL.
init(fileURLWithPath: String, relativeTo: URL?
) Initializes a newly created file URL referencing the local file or directory at path, relative to a base URL.
init(from: Decoder
) throws init?(string: String
) Initialize with string.
init?(string: String, relativeTo: URL?
) Initialize with string, relative to another URL.
var absoluteString: String
Returns the absolute string for the URL.
var absoluteURL: URL
Returns the absolute URL.
var baseURL: URL?
Returns the base URL.
var dataRepresentation: Data
Returns the data representation of the URL’s relativeString.
var debugDescription: String
var description: String
var fragment: String?
If the URL conforms to RFC 1808 (the most common form of URL), returns the fragment component of the URL; otherwise it returns nil.
var hasDirectoryPath: Bool
Returns true if the URL path represents a directory.
var host: String?
If the URL conforms to RFC 1808 (the most common form of URL), returns the host component of the URL; otherwise it returns nil.
var isFileURL: Bool
Returns true if the scheme is
file:
.var lastPathComponent: String
Returns the last path component of the URL, or an empty string if the path is an empty string.
var password: String?
If the URL conforms to RFC 1808 (the most common form of URL), returns the password component of the URL; otherwise it returns nil.
var path: String
If the URL conforms to RFC 1808 (the most common form of URL), returns the path component of the URL; otherwise it returns an empty string.
var pathComponents: [String]
Returns the path components of the URL, or an empty array if the path is an empty string.
var pathExtension: String
Returns the path extension of the URL, or an empty string if the path is an empty string.
var playgroundDescription: Any
var port: Int?
If the URL conforms to RFC 1808 (the most common form of URL), returns the port component of the URL; otherwise it returns nil.
var query: String?
If the URL conforms to RFC 1808 (the most common form of URL), returns the query of the URL; otherwise it returns nil.
var relativePath: String
If the URL conforms to RFC 1808 (the most common form of URL), returns the relative path of the URL; otherwise it returns nil.
var relativeString: String
The relative portion of a URL.
var scheme: String?
Returns the scheme of the URL.
var standardized: URL
Returns a
URL
with any instances of “..” or “.” removed from its path.var standardizedFileURL: URL
Standardizes the path of a file URL.
var user: String?
If the URL conforms to RFC 1808 (the most common form of URL), returns the user component of the URL; otherwise it returns nil.
static func == (URL, URL
) -> Bool func appendPathComponent(String
) Appends a path component to the URL.
func appendPathComponent(String, isDirectory: Bool
) Appends a path component to the URL.
func appendPathExtension(String
) Appends the given path extension to self.
func appendingPathComponent(String
) -> URL Returns a URL constructed by appending the given path component to self.
func appendingPathComponent(String, isDirectory: Bool
) -> URL Returns a URL constructed by appending the given path component to self.
func appendingPathExtension(String
) -> URL Returns a URL constructed by appending the given path extension to self.
func checkResourceIsReachable(
) throws -> Bool Returns whether the URL’s resource exists and is reachable.
func deleteLastPathComponent(
) Removes the last path component from self.
func deletePathExtension(
) Removes any path extension from self.
func deletingLastPathComponent(
) -> URL Returns a URL constructed by removing the last path component of self.
func deletingPathExtension(
) -> URL Returns a URL constructed by removing any path extension.
func encode(to: Encoder
) throws func hash(into: inout Hasher
) func removeAllCachedResourceValues(
) Removes all cached resource values and all temporary resource values from the URL object.
func removeCachedResourceValue(forKey: URLResourceKey
) Removes the cached resource value identified by a given resource value key from the URL object.
func resolveSymlinksInPath(
) Resolves any symlinks in the path of a file URL.
func resolvingSymlinksInPath(
) -> URL Resolves any symlinks in the path of a file URL.
func resourceValues(forKeys: Set<URLResourceKey>
) throws -> URLResourceValues Return a collection of resource values identified by the given resource keys.
func setResourceValues(URLResourceValues
) throws Sets the resource value identified by a given resource key.
func setTemporaryResourceValue(Any, forKey: URLResourceKey
) Sets a temporary resource value on the URL object.
func standardize(
) Standardizes the path of a file URL.
func withUnsafeFileSystemRepresentation<ResultType>((UnsafePointer<Int8>?) throws -> ResultType
) rethrows -> ResultType Passes the URL’s path in file system representation to
block
.typealias ReferenceType
Features
Extension in AsyncHTTPClient
Members
init?(httpURLWithSocketPath: String, uri: String
) Initializes a newly created HTTP URL connecting to a unix domain socket path. The socket path is encoded as the URL’s host, replacing percent encoding invalid path characters, and will use the “http+unix” scheme.
init?(httpsURLWithSocketPath: String, uri: String
) Initializes a newly created HTTPS URL connecting to a unix domain socket path over TLS. The socket path is encoded as the URL’s host, replacing percent encoding invalid path characters, and will use the “https+unix” scheme.