---
title: "init(contentsOfFileAtURL:uniformTypeIdentifier:)"
framework: xctest
role: symbol
role_heading: Initializer
path: "xctest/xctattachment/init(contentsoffileaturl:uniformtypeidentifier:)"
---

# init(contentsOfFileAtURL:uniformTypeIdentifier:)

Creates an attachment from the contents of an existing file on disk, with a custom UTI.

## Declaration

```swift
convenience init(contentsOfFileAtURL url: URL, uniformTypeIdentifier identifier: String)
```

## Parameters

- `url`: The file URL from which data should be read to create the new attachment.
- `identifier`: A custom UTI to represent the file’s content type.

## Discussion

Discussion The attachment’s name property is the file name of the provided url. note: Use this initializer with files only. To create an attachment from a directory, use init(compressedContentsOfDirectoryAtURL:).

## See Also

### Creating Attachments from Files and Folders

- [init(contentsOfFileAtURL:)](xctest/xctattachment/init(contentsoffileaturl:).md)
- [init(compressedContentsOfDirectoryAtURL:)](xctest/xctattachment/init(compressedcontentsofdirectoryaturl:).md)
