---
title: "withUnsafeBytes(_:)"
framework: testing
role: symbol
role_heading: Instance Method
path: "testing/attachment/withunsafebytes(_:)"
---

# withUnsafeBytes(_:)

Call a function and pass a buffer representing the value of this instance’s attachableValue property to it.

## Declaration

```swift
borrowing func withUnsafeBytes<R>(_ body: (UnsafeRawBufferPointer) throws -> R) throws -> R
```

## Parameters

- `body`: A function to call. A temporary buffer containing a data representation of this instance is passed to it.

## Return Value

Return Value Whatever is returned by body.

## Discussion

Discussion note: Whatever is thrown by body, or any error that prevented the creation of the buffer. The testing library uses this function when saving an attachment. This function calls the withUnsafeBytes(for:_:) function on this attachment’s attachableValue property.
