<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFURLCopyLastPathComponent(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@F@CFURLCopyLastPathComponent"
  },
  "title" : "CFURLCopyLastPathComponent(_:)"
}
-->

# CFURLCopyLastPathComponent(_:)

Returns the last path component of a given URL.

```
func CFURLCopyLastPathComponent(_ url: CFURL!) -> CFString!
```

## Parameters

`url`

The `CFURL` object to examine.

## Return Value

The last path component of `url`. Ownership follows the create rule. See [The Create Rule](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-103029).

## Discussion

Note that if there is no last path component, this function returns an empty string. In the code sample shown, `lastPathComponent` is an empty string.

```objc
CFStringRef urlString = CFSTR("http://www.apple.com");
CFURLRef url = CFURLCreateWithString(NULL, urlString, NULL);
CFStringRef lastPathComponent = CFURLCopyLastPathComponent (url);
```

If `urlString` were created with `CFSTR("http://www.apple.com/")`, then `lastPathComponent` would be a `CFString` object containing the character “`/`”.

See also [`CFURLCopyPathExtension(_:)`](/documentation/CoreFoundation/CFURLCopyPathExtension(_:)).

---

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)