---
title: "copyBytes(to:from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/data/copybytes(to:from:)-8qk4r"
---

# copyBytes(to:from:)

Copies a subset of the contents of the data to memory.

## Declaration

```swift
func copyBytes(to pointer: UnsafeMutablePointer<UInt8>, from range: Range<Data.Index>)
```

## Parameters

- `pointer`: A pointer to the buffer you wish to copy the bytes into.
- `range`: The range in the Data to copy.

## Discussion

Discussion warning: This method does not verify that the contents at pointer have enough space to hold the required number of bytes.

## See Also

### Accessing Underlying Memory

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