Instance Property

lastPathComponent

The last path component of the receiver.

Declaration

var lastPathComponent: String { get }

Discussion

Path components are alphanumeric strings delineated by the path separator (slash “/”) or the beginning or end of the path string. Multiple path separators at the end of the string are stripped.

The following table illustrates the effect of lastPathComponent on a variety of different paths:

Receiver’s String Value

String Returned

/tmp/scratch.tiff

scratch.tiff

/tmp/scratch

scratch

/tmp/

tmp

scratch///

scratch

/

“/”

Note that this method only works with file paths (not, for example, string representations of URLs).

See Also

Related Symbols

var pathComponents: [String]

The file-system path components of the receiver.