<!--
{
  "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/appending(component:directoryHint:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation3URLV9appending9component13directoryHintACx_AC09DirectoryF0OtSyRzlF"
  },
  "title" : "appending(component:directoryHint:)"
}
-->

# appending(component:directoryHint:)

Returns a URL by appending the specified path component to the URL, with a hint for handling directory awareness.

```
func appending<S>(component: S, directoryHint: URL.DirectoryHint = .inferFromPath) -> URL where S : StringProtocol
```

## Parameters

`component`

The path component to add.

`directoryHint`

A hint to the initializer to indicate whether the path is a directory, or to instruct the method to make this determination. Defaults to [`URL.DirectoryHint.inferFromPath`](/documentation/Foundation/URL/DirectoryHint/inferFromPath).

## Return Value

A new URL that appends the specified path to the original URL.

## Discussion

This method percent-encodes any path separators (`/`) in the path component before appending the component to the path. If you don’t want this encoding, use [`appending(path:directoryHint:)`](/documentation/Foundation/URL/appending(path:directoryHint:)) instead.

---

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)