---
title: Attachable
framework: testing
role: symbol
role_heading: Protocol
path: testing/attachable
---

# Attachable

A protocol describing a type whose instances can be recorded and saved as part of a test run.

## Declaration

```swift
protocol Attachable : ~Copyable
```

## Mentioned in

Migrating a test from XCTest

## Overview

Overview To attach an attachable value to a test, pass it to record(_:named:sourceLocation:). To further configure an attachable value before you attach it, use it to initialize an instance of Attachment and set its properties before passing it to record(_:sourceLocation:). The testing library provides default conformances to this protocol for a variety of standard library types. Most user-defined types do not need to conform to this protocol. A type should conform to this protocol if it can be represented as a sequence of bytes that would be diagnostically useful if a test fails. If a type cannot conform directly to this protocol (such as a non-final class or a type declared in a third-party module), you can create a wrapper type that conforms to AttachableWrapper to act as a proxy.

## Topics

### Instance Properties

- [estimatedAttachmentByteCount](testing/attachable/estimatedattachmentbytecount.md)

### Instance Methods

- [preferredName(for:basedOn:)](testing/attachable/preferredname(for:basedon:).md)
- [withUnsafeBytes(for:_:)](testing/attachable/withunsafebytes(for:_:).md)

## Relationships

### Inherited By

- [AttachableWrapper](testing/attachablewrapper.md)

## See Also

### Attaching values to tests

- [Attachment](testing/attachment.md)
- [AttachableWrapper](testing/attachablewrapper.md)
