<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/UnsafeMutableRawBufferPointer/copyBytes(from:)-6hg9u",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:Sw9copyBytes4fromyx_tSlRzs5UInt8V7ElementRtzlF"
  },
  "title" : "copyBytes(from:)"
}
-->

# copyBytes(from:)

Copies from a collection of `UInt8` into this buffer’s memory.

```
func copyBytes<C>(from source: C) where C : Collection, C.Element == UInt8
```

## Parameters

`source`

A collection of `UInt8` elements. `source.count` must
be less than or equal to this buffer’s `count`.

## Discussion

If the first `source.count` bytes of memory referenced by this buffer
are bound to a type `T`, then `T` must be a trivial type,
the underlying pointer must be properly aligned for accessing `T`,
and `source.count` must be a multiple of `MemoryLayout<T>.stride`.

After calling `copyBytes(from:)`, the first `source.count` bytes of memory
referenced by this buffer are initialized to raw bytes. If the memory is
bound to type `T`, then it contains values of type `T`.

---

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)