Skip to content

Instance Method

path(percentEncoded:)

iOS 16.0+ iPadOS 16.0+ Mac Catalyst 16.0+ macOS 13.0+ tvOS 16.0+ watchOS 9.0+
Returns the path component of the URL, optionally removing any percent-encoding.
func path(percentEncoded: Bool = true) -> String

Parameters

percentEncoded

Whether the path should be percent encoded, defaults to true.

Return Value

The path component of the URL.

Discussion

The system doesn’t allow certain characters in the URL path component, so URL percent-encodes those characters to create a valid URL. Calling this function with percentEncoded = false removes any percent-encoding and returns the unencoded path.

If the URL’s path component is empty, this method returns an empty string.

Note

This function resolves against the base URL.