appendingPathComponent(_:conformingTo:)
Returns a URL by appending the specified path component with the file extension for a uniform type identifier.
Declaration
func appendingPathComponent(_ partialName: String, conformingTo contentType: UTType) -> URLParameters
- 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 image, respectively, the function returns a URL with an appended path component of puppy.jpg. However, if the inputs are puppy.jpg and 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() method first.
If the function can’t append the path component, it returns an unchanged URL.
For more information about types, see Uniform Type Identifiers.