Fixes example snippets in Array.swift considering endianness

This commit is contained in:
Valeriy Van
2020-08-24 17:14:24 +02:00
parent ec72db1d8a
commit cdba663d80
3 changed files with 21 additions and 9 deletions

View File

@@ -1361,7 +1361,7 @@ extension ContiguousArray {
/// and enums.
///
/// The following example copies bytes from the `byteValues` array into
/// `numbers`, an array of `Int`:
/// `numbers`, an array of `Int32`:
///
/// var numbers: [Int32] = [0, 0]
/// var byteValues: [UInt8] = [0x01, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00]
@@ -1373,6 +1373,8 @@ extension ContiguousArray {
/// }
/// // numbers == [1, 2]
///
/// - Note: This example shows the behavior on a little-endian platform.
///
/// The pointer passed as an argument to `body` is valid only for the
/// lifetime of the closure. Do not escape it from the closure for later
/// use.
@@ -1410,12 +1412,14 @@ extension ContiguousArray {
/// The following example copies the bytes of the `numbers` array into a
/// buffer of `UInt8`:
///
/// var numbers = [1, 2, 3]
/// var numbers: [Int32] = [1, 2, 3]
/// var byteBuffer: [UInt8] = []
/// numbers.withUnsafeBytes {
/// byteBuffer.append(contentsOf: $0)
/// }
/// // byteBuffer == [1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, ...]
/// // byteBuffer == [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]
///
/// - Note: This example shows the behavior on a little-endian platform.
///
/// - Parameter body: A closure with an `UnsafeRawBufferPointer` parameter
/// that points to the contiguous storage for the array.