<!--
{
  "availability" : [

  ],
  "documentType" : "symbol",
  "framework" : "XCTest",
  "identifier" : "/documentation/XCTest/XCTAttachment/init(uniformTypeIdentifier:name:payload:userInfo:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "XCTest"
    ],
    "preciseIdentifier" : "c:objc(cs)XCTAttachment(im)initWithUniformTypeIdentifier:name:payload:userInfo:"
  },
  "title" : "init(uniformTypeIdentifier:name:payload:userInfo:)"
}
-->

# init(uniformTypeIdentifier:name:payload:userInfo:)

Creates an attachment containing the provided data payload, optionally with a custom UTI, name, and user-provided metadata dictionary.

```
init(uniformTypeIdentifier identifier: String?, name: String?, payload: Data?, userInfo: [AnyHashable : Any]? = nil)
```

## Parameters

`identifier`

An optional custom UTI to represent the data’s content type.

`name`

An optional name for the attachment, to be used in Xcode’s test reports.

`payload`

The data to wrap as an attachment.

`userInfo`

An optional dictionary of user-provided metadata to associate with the attachment.

## Discussion

Creates an attachment with a [`uniformTypeIdentifier`](/documentation/XCTest/XCTAttachment/uniformTypeIdentifier) of `"public.data"` if the `identifier` parameter is `nil`.

---

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)