<!--
{
  "availability" : [
    "Swift: -"
  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTAttachment/init(contentsOfFileAtURL:uniformTypeIdentifier:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTAttachment(cm)attachmentWithContentsOfFileAtURL:uniformTypeIdentifier:::SYNTHESIZED::c:objc(cs)XCTAttachment"
  },
  "title" : "init(contentsOfFileAtURL:uniformTypeIdentifier:)"
}
-->

# init(contentsOfFileAtURL:uniformTypeIdentifier:)

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

```
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

The attachment’s [`name`](/documentation/XCTest/XCTAttachment/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 ``doc://com.apple.xctest/documentation/XCTest/XCTAttachment/init(compressedContentsOfDirectoryAtURL:)``.

---

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)