<!--
{
  "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/Slice/copyBytes(from:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s5SliceVsSwRszrlE9copyBytes4fromyqd___tSlRd__s5UInt8V7ElementRtd__lF"
  },
  "title" : "copyBytes(from:)"
}
-->

# copyBytes(from:)

Copies from a collection of `UInt8` into this buffer slice’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 slice’s `count`.

## Discussion

If the first `source.count` bytes of memory referenced by
this buffer slice 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 slice 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)