Represents an individual, non-root component of a file path.
Components can be one of the special directory components (`.` or `..`)
or a file or directory name. Components are never empty and never
contain the directory separator.
Example:
var path: FilePath = "/tmp"
let file: FilePath.Component = "foo.txt"
file.kind == .regular // true
file.extension // "txt"
path.append(file) // path is "/tmp/foo.txt"
Members (13)
get · iOS 15.0+
description
TypeScript
get description(): string
Swift declaration
var description: String { get }
A textual representation of the path component.
If the content of the path component isn't a well-formed Unicode string,
this replaces invalid bytes with U+FFFD. See `String.init(decoding:)`.
Creates a file path component by copying bytes from a null-terminated
platform string.
Returns `nil` if `platformString` is empty, is a root, or has more than
one component in it.
- Parameter platformString: A pointer to a null-terminated platform
string.
Creates a file path component by copying bytes from a null-terminated
platform string. It is a precondition that a null byte indicates the end of
the string. The absence of a null byte will trigger a runtime error.
Returns `nil` if `platformString` is empty, is a root, or has more than
one component in it.
- Note It is a precondition that `platformString` must be null-terminated.
The absence of a null byte will trigger a runtime error.
- Parameter platformString: A null-terminated platform string.
Omit the output parameters from the call. The result contains $ret and $out, with platformString inside $out.
get · iOS 15.0+
debugDescription
TypeScript
get debugDescription(): string
Swift declaration
var debugDescription: String { get }
A textual representation of the path component, suitable for debugging.
If the content of the path component isn't a well-formed Unicode string,
this replaces invalid bytes with U+FFFD. See `String.init(decoding:)`.
func withPlatformString<Result>(_ body: (UnsafePointer<CInterop.PlatformChar>) throws -> Result) rethrows -> Result
Calls the given closure with a pointer to the contents of the file path
component, represented as a null-terminated platform string.
If this is not the last component of a path, an allocation will occur in
order to add the null terminator.
- Parameter body: A closure with a pointer parameter
that points to a null-terminated platform string.
If `body` has a return value,
that value is also used as the return value for this method.
- Returns: The return value, if any, of the `body` closure parameter.
The pointer passed as an argument to `body` is valid
only during the execution of this method.
Don't try to store the pointer for later use.
get · iOS 15.0+
kind
TypeScript
get kind(): FilePath_Component_Kind
Swift declaration
var kind: FilePath.Component.Kind { get }
The kind of this component
get · iOS 15.0+
stem
TypeScript
get stem(): string
Swift declaration
var stem: String { get }
The non-extension portion of this file or directory component.
Examples:
* `foo.txt => foo`
* `foo.tar.gz => foo.tar`
* `Foo.app => Foo`
* `.hidden => .hidden`
* `.. => ..`
get · iOS 15.0+
string
TypeScript
get string(): string
Swift declaration
var string: String { get }
Creates a string by interpreting the component’s content as UTF-8 on Unix
and UTF-16 on Windows.
This property is equivalent to calling `String(decoding: component)`.
get · iOS 15.0+
extension
TypeScript
get extension(): (string) | null
Swift declaration
var `extension`: String? { get }
The extension of this file or directory component.
If `self` does not contain a `.` anywhere, or only
at the start, returns `nil`. Otherwise, returns everything after the dot.
Examples:
* `foo.txt => txt`
* `foo.tar.gz => gz`
* `Foo.app => app`
* `.hidden => nil`
* `.. => nil`