Contents

path(percentEncoded:)

Returns the path component of the URL, optionally removing any percent-encoding.

Declaration

func path(percentEncoded: Bool = true) -> String

Parameters

  • percentEncoded:

    A Boolean value that indicates whether the URL percent-encodes any unreserved characters. Defaults to true.

Return Value

The path component of the URL, optionally percent-encoding any unreserved characters.

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.

See Also

Accessing the parts of a URL