<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 8.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/Data/copyBytes(to:from:)-8qk4r",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation4DataV9copyBytes2to4fromySpys5UInt8VG_SnySiGtF"
  },
  "title" : "copyBytes(to:from:)"
}
-->

# copyBytes(to:from:)

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

```
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

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)