小编Joh*_*cke的帖子

如何在Swift 3中将UInt16转换为UInt8?

我想将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))
    }
Run Code Online (Sandbox Code Playgroud)

type-conversion uint16 swift uint8array

1
推荐指数
2
解决办法
1494
查看次数

标签 统计

swift ×1

type-conversion ×1

uint16 ×1

uint8array ×1