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

# withUnsafeBytes(_:)

Accesses the raw bytes in the data’s buffer.

## Declaration

```swift
func withUnsafeBytes<ResultType, ContentType>(_ body: (UnsafePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
```

## Discussion

Discussion warning: The byte pointer argument should not be stored and used outside of the lifetime of the call to the closure.

## See Also

### Accessing Underlying Memory

- [withUnsafeMutableBytes(_:)](foundation/data/withunsafemutablebytes(_:)-7ac1g.md)
- [copyBytes(to:count:)](foundation/data/copybytes(to:count:).md)
- [copyBytes(to:from:)](foundation/data/copybytes(to:from:)-8qk4r.md)
- [copyBytes(to:from:)](foundation/data/copybytes(to:from:)-4o6zj.md)
