<!--
{
  "availability" : [
    "iOS: 14.0.0 -",
    "iPadOS: 14.0.0 -",
    "macCatalyst: 14.0.0 -",
    "macOS: 11.0.0 -",
    "tvOS: 14.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 7.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURL/appendingPathComponent(_:conformingTo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURL(im)URLByAppendingPathComponent:conformingToType:"
  },
  "title" : "appendingPathComponent(_:conformingTo:)"
}
-->

# appendingPathComponent(_:conformingTo:)

Returns a URL by appending the specified path component with the file extension for a uniform type identifier.

```
func appendingPathComponent(_ partialName: String, conformingTo contentType: UTType) -> URL
```

## Parameters

`partialName`

The partial name to append.

`contentType`

A uniform type identifier the resulting conforms to.

## Return Value

A new URL with the partial name and the type’s preferred extension appended.

## Discussion

Use this method when you want to mix partial input from a user or other source, and need to produce a complete filename suitable for that input. For example, if you download a file from the internet and know its MIME type, you can use this method to ensure the URL has the correct filename extension where you save the file.

If `partialName` already has a path extension, and that path extension is valid for file system objects of type `contentType`, the function doesn’t add an extension before appending it to the URL. For example, if the inputs are `puppy.jpg` and <doc://com.apple.documentation/documentation/UniformTypeIdentifiers/UTType-swift.struct/image>, respectively, the function returns a URL with an appended path component of `puppy.jpg`. However, if the inputs are `puppy.jpg` and <doc://com.apple.documentation/documentation/UniformTypeIdentifiers/UTType-swift.struct/plainText>, respectively, the function returns a URL with an appended path component of `puppy.jpg.txt`. If you want to replace any existing path extension, use the [`deletePathExtension()`](/documentation/Foundation/URL/deletePathExtension()) method first.

If the function can’t append the path component, it returns an unchanged URL.

> Note:
> The modified URL has a directory path if `contentType` conforms to <doc://com.apple.documentation/documentation/UniformTypeIdentifiers/UTType-swift.struct/directory>.

For more information about types, see <doc://com.apple.documentation/documentation/UniformTypeIdentifiers>.

---

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)