DirectoryHint
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
enum DirectoryHint
enum DirectoryHint
import FoundationEssentials
struct 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.
case checkFileSystem
Specifies that URL
should check with the file system to determine whether it references a directory
case inferFromPath
Specifies that URL
should infer whether it references a directory based on whether it has a trailing slash
case isDirectory
Specifies that the URL
does reference a directory
case notDirectory
Specifies that the URL
does not reference a directory
init?(dataRepresentation: Data, relativeTo url: URL?, isAbsolute: Bool = false)
Initializes a newly created URL using the contents of the given data, relative to a base URL.
init(filePath path: String, directoryHint: URL.DirectoryHint = .inferFromPath, relativeTo base: URL? = nil)
Initializes a newly created file URL referencing the local file or directory at path, relative to a base URL.
init(fileURLWithFileSystemRepresentation path: UnsafePointer<Int8>, isDirectory: Bool, relativeTo baseURL: 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 path: String)
Initializes a newly created file URL referencing the local file or directory at path.
init(fileURLWithPath path: String, isDirectory: Bool)
Initializes a newly created file URL referencing the local file or directory at path.
init(fileURLWithPath path: String, isDirectory: Bool, relativeTo base: URL?)
Initializes a newly created file URL referencing the local file or directory at path, relative to a base URL.
init(fileURLWithPath path: String, relativeTo base: URL?)
Initializes a newly created file URL referencing the local file or directory at path, relative to a base URL.
init(from decoder: any Decoder) throws
init?(string: String)
Initialize with string.
init?(string: String, encodingInvalidCharacters: Bool)
Initialize with a URL string and the option to add (or skip) IDNA- and percent-encoding of invalid characters.
init?(string: String, relativeTo url: URL?)
Initialize with string, relative to another URL.
static var homeDirectory: URL { get }
The home directory for the current user (~/). Complexity: O(1)
static var temporaryDirectory: URL { get }
The temporary directory for the current user. Complexity: O(1)
static func currentDirectory() -> URL
The working directory of the current process. Calling this property will issue a getcwd
syscall.
static func homeDirectory(forUser user: String) -> URL?
Returns the home directory for the specified user.
var absoluteString: String { get }
Returns the absolute string for the URL.
var absoluteURL: URL { get }
Returns the absolute URL.
var baseURL: URL? { get }
Returns the base URL.
var dataRepresentation: Data { get }
Returns the data representation of the URL’s relativeString.
var debugDescription: String { get }
var description: String { get }
var fragment: String? { get }
Returns the fragment component of the URL if present, otherwise returns nil
.
var hasDirectoryPath: Bool { get }
Returns true if the URL path represents a directory.
var host: String? { get }
Returns the host component of the URL if present, otherwise returns nil
.
var isFileURL: Bool { get }
Returns true if the scheme is file:
.
var lastPathComponent: String { get }
Returns the last path component of the URL, or an empty string if the path is an empty string.
var password: String? { get }
Returns the password component of the URL if present, otherwise returns nil
.
var path: String { get }
Returns the path component of the URL if present, otherwise returns an empty string.
var pathComponents: [String] { get }
Returns the path components of the URL, or an empty array if the path is an empty string.
var pathExtension: String { get }
Returns the path extension of the URL, or an empty string if the path is an empty string.
var port: Int? { get }
Returns the port component of the URL if present, otherwise returns nil
.
var query: String? { get }
Returns the query component of the URL if present, otherwise returns nil
.
var relativePath: String { get }
Returns the relative path of the URL if present, otherwise returns an empty string. This is the same as path
if baseURL
is nil
.
var relativeString: String { get }
Returns the relative portion of a URL.
var scheme: String? { get }
Returns the scheme of the URL.
var standardized: URL { get }
Returns a URL
with any instances of “..” or “.” removed from its path.
var standardizedFileURL: URL { get }
Standardizes the path of a file URL.
var user: String? { get }
Returns the user component of the URL if present, otherwise returns nil
.
static func == (lhs: URL, rhs: URL) -> Bool
mutating func append<S>(component: S, directoryHint: URL.DirectoryHint = .inferFromPath) where S : StringProtocol
Appends a path component to the receiver. The path component is first percent-encoded before being appended to the receiver.
mutating func append<S>(components: S..., directoryHint: URL.DirectoryHint = .inferFromPath) where S : StringProtocol
Appends a varidic list of path components to the URL.
mutating func append<S>(path: S, directoryHint: URL.DirectoryHint = .inferFromPath) where S : StringProtocol
Appends a path to the receiver.
mutating func append(queryItems: [URLQueryItem])
Appends a list of URLQueryItem
to the receiver.
mutating func appendPathComponent(_ pathComponent: String)
Appends a path component to the URL.
mutating func appendPathComponent(_ pathComponent: String, isDirectory: Bool)
Appends a path component to the URL.
mutating func appendPathExtension(_ pathExtension: String)
Appends the given path extension to self.
func appending<S>(component: S, directoryHint: URL.DirectoryHint = .inferFromPath) -> URL where S : StringProtocol
Returns a URL constructed by appending the given path component to self. The path component is first percent-encoded before being appended to the receiver.
func appending<S>(components: S..., directoryHint: URL.DirectoryHint = .inferFromPath) -> URL where S : StringProtocol
Returns a URL constructed by appending the given varidic list of path components to self.
func appending<S>(path: S, directoryHint: URL.DirectoryHint = .inferFromPath) -> URL where S : StringProtocol
Returns a URL constructed by appending the given path to self.
func appending(queryItems: [URLQueryItem]) -> URL
Returns a URL constructed by appending the given list of URLQueryItem
to self.
func appendingPathComponent(_ pathComponent: String) -> URL
Returns a URL constructed by appending the given path component to self.
func appendingPathComponent(_ pathComponent: String, isDirectory: Bool) -> URL
Returns a URL constructed by appending the given path component to self.
func appendingPathExtension(_ pathExtension: String) -> URL
Returns a URL constructed by appending the given path extension to self.
mutating func deleteLastPathComponent()
Returns a URL constructed by removing the last path component of self.
mutating func deletePathExtension()
Returns a URL constructed by removing any path extension.
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: any Encoder) throws
func fragment(percentEncoded: Bool = true) -> String?
Returns the password component of the URL if present, otherwise returns nil
.
func hash(into hasher: inout Hasher)
func host(percentEncoded: Bool = true) -> String?
Returns the host component of the URL if present, otherwise returns nil
.
func password(percentEncoded: Bool = true) -> String?
Returns the password component of the URL if present, otherwise returns nil
.
func path(percentEncoded: Bool = true) -> String
Returns the path component of the URL if present, otherwise returns an empty string.
func query(percentEncoded: Bool = true) -> String?
Returns the password component of the URL if present, otherwise returns nil
.
mutating 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.
mutating func standardize()
Standardizes the path of a file URL by removing dot segments.
func user(percentEncoded: Bool = true) -> String?
Returns the user component of the URL if present, otherwise returns nil
.
func withUnsafeFileSystemRepresentation<ResultType>(_ block: (UnsafePointer<Int8>?) throws -> ResultType) rethrows -> ResultType
Passes the URL’s path in file system representation to block
.
protocol Equatable
A type that can be compared for value equality.
protocol Hashable : Equatable
A type that can be hashed into a Hasher
to produce an integer hash value.
protocol Sendable
static func != (lhs: Self, rhs: Self) -> Bool
Returns a Boolean value indicating whether two values are not equal.