Path
-
A
Pathrepresents an absolute path on a filesystem.All functions on
Pathare chainable and short to facilitate doing sequences of file operations in a concise manner.PathsupportsCodable, and can be configured to encode paths relatively.Sorting a
Sequenceof paths will return the locale-aware sort order, which will give you the same order as Finder.Converting from a
Stringis a common first step, here are the recommended ways to do that:let p1 = Path.root/pathString let p2 = Path.root/url.path let p3 = Path.cwd/relativePathString let p4 = Path(userInput) ?? Path.cwd/userInputIf you are constructing paths from static-strings we provide support for dynamic members:
let p1 = Path.root.usr.bin.ls // => /usr/bin/lsHowever we only provide this support off of the static members like
rootdue to the anti-pattern where Path.swift suddenly feels like Javascript otherwise.See moreNote
APathdoes not necessarily represent an actual filesystem entry.Declaration
Swift
public struct Path : Pathishextension Path: Codableextension Path: CustomStringConvertibleextension Path: CustomDebugStringConvertible -
A type that represents a filesystem path, if you conform your type to
See morePathishit is your responsibility to ensure the string is correctly normalizedDeclaration
Swift
public protocol Pathish : Comparable, Hashable
View on GitHub
Path Reference