---
title: "withUnsafeMutableBytes(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/data/withunsafemutablebytes(_:)-7ac1g"
---

# withUnsafeMutableBytes(_:)

Mutates the raw bytes in the data’s buffer.

## Declaration

```swift
mutating func withUnsafeMutableBytes<ResultType, ContentType>(_ body: (UnsafeMutablePointer<ContentType>) throws -> ResultType) rethrows -> ResultType
```

## Discussion

Discussion This function assumes that you are mutating the contents. 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

- [withUnsafeBytes(_:)](foundation/data/withunsafebytes(_:).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)
