copyBytes(to:from:)
Copies a range of the bytes from the type into a typed memory buffer.
Declaration
@discardableResult func copyBytes<DestinationType, R>(to: UnsafeMutableBufferPointer<DestinationType>, from: R) -> Int where R : RangeExpression, Self.Index == R.BoundParameters
- to:
A typed pointer to the buffer you want to copy the bytes into.
- from:
The range of bytes to copy.
Return Value
The number of bytes copied.
Discussion
The following example copies the source bytes that the provided range identifies into the beginning of the specified typed memory buffer:
let source: [UInt8] = [0, 1, 2]
var dest: [UInt8] = [0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF]
dest.withUnsafeMutableBufferPointer { typedMemBuffer in
source.copyBytes(to: typedMemBuffer, from: 1...2)
}
// dest = [0x01, 0x02, 0xFF, 0xFF, 0xFF, 0xFF]