<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 16.0.0 -",
    "macOS: 13.0.0 -",
    "tvOS: 16.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 9.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/URL/path(percentEncoded:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV4path14percentEncodedSSSb_tF"
  },
  "title" : "path(percentEncoded:)"
}
-->

# path(percentEncoded:)

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

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

---

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)