---
title: "copyBytes(to:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/dataprotocol/copybytes(to:)-52wps"
---

# copyBytes(to:)

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

## Declaration

```swift
@discardableResult func copyBytes<DestinationType>(to ptr: UnsafeMutableBufferPointer<DestinationType>) -> Int
```

## Parameters

- `ptr`: A typed pointer to the buffer you want to copy the bytes into.

## Return Value

Return Value The number of bytes copied.

## Discussion

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

## See Also

### Copying Underlying Bytes

- [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:)-1ol47.md)
- [copyBytes(to:from:)](foundation/dataprotocol/copybytes(to:from:)-1y839.md)
