---
title: "copyBytes(to:from:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/dataprotocol/copybytes(to:from:)-1ol47"
---

# copyBytes(to:from:)

Copies a range of the bytes from the type into a typed memory buffer.

## Declaration

```swift
@discardableResult func copyBytes<DestinationType, R>(to: UnsafeMutableBufferPointer<DestinationType>, from: R) -> Int where R : RangeExpression, Self.Index == R.Bound
```

## Parameters

- `to`: A typed pointer to the buffer you want to copy the bytes into.
- `from`: The range of bytes to copy.

## Return Value

Return Value The number of bytes copied.

## Discussion

Discussion The following example copies the source bytes that the provided range identifies into the beginning of the specified typed memory buffer: let source: [UInt8] = [0, 1, 2] var dest: [UInt8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF] dest.withUnsafeMutableBufferPointer { typedMemBuffer in     source.copyBytes(to: typedMemBuffer, from: 1...2) } // dest = [0x01, 0x02, 0xFF, 0xFF, 0xFF, 0xFF]

## See Also

### Copying Underlying Bytes

- [copyBytes(to:)](foundation/dataprotocol/copybytes(to:)-52wps.md)
- [copyBytes(to:)](foundation/dataprotocol/copybytes(to:)-3mk27.md)
- [copyBytes(to:count:)](foundation/dataprotocol/copybytes(to:count:)-6krsm.md)
- [copyBytes(to:count:)](foundation/dataprotocol/copybytes(to:count:)-29t5.md)
- [copyBytes(to:from:)](foundation/dataprotocol/copybytes(to:from:)-1y839.md)
