<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSString/lastPathComponent",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSString(py)lastPathComponent"
  },
  "title" : "lastPathComponent"
}
-->

# lastPathComponent

The last path component of the receiver.

```
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`](/documentation/Foundation/NSString/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).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)