Contents

copyBytes(to:count:)

Copies the provided number of bytes from the start of the type into a typed memory buffer.

Declaration

@discardableResult func copyBytes<DestinationType>(to: UnsafeMutableBufferPointer<DestinationType>, count: Int) -> Int

Parameters

  • to:

    A typed pointer to the buffer you want to copy the bytes into.

  • count:

    The number of bytes to copy.

Return Value

The number of bytes copied.

Discussion

The following example copies the number of bytes that count identified from the beginning of the raw 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: 1)
    // count == 1
}
// dest = [0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]

See Also

Copying Underlying Bytes