我想将 UInt16 转换为 UInt8 数组,但收到以下错误消息:
'init' 不可用:使用 'withMemoryRebound(to:capacity:_)' 临时将内存视为另一种布局兼容类型。
编码:
let statusByte: UInt8 = UInt8(status)
let lenghtByte: UInt16 = UInt16(passwordBytes.count)
var bigEndian = lenghtByte.bigEndian
let bytePtr = withUnsafePointer(to: &bigEndian) {
UnsafeBufferPointer<UInt8>(start: UnsafePointer($0), count: MemoryLayout.size(ofValue: bigEndian))
}