Contents

appendPathComponent(_:conformingTo:)

Appends a path component to the URL that conforms to a uniform type identifier.

Declaration

mutating func appendPathComponent(_ partialName: String, conformingTo contentType: UTType)

Parameters

  • partialName:

    The name of path component without the type.

  • contentType:

    A uniform type identifier that determines the default extension.

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 jpeg, 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.

See Also

Adding path components