Contents

CFURLCopyLastPathComponent(_:)

Returns the last path component of a given URL.

Declaration

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.

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.

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(_:).

See Also

Accessing the Parts of a URL