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 |
|---|---|
“ | “ |
“ | “ |
“ | “ |
“ | “ |
“ | “/” |
Note that this method only works with file paths (not, for example, string representations of URLs).
See Also
Working with Paths
path(withComponents:)pathComponentscompletePath(into:caseSensitive:matchesInto:filterTypes:)fileSystemRepresentationgetFileSystemRepresentation(_:maxLength:)isAbsolutePathpathExtensionabbreviatingWithTildeInPathappendingPathComponent(_:)appendingPathExtension(_:)deletingLastPathComponentdeletingPathExtensionexpandingTildeInPathresolvingSymlinksInPathstandardizingPath