如何将 UnsafeMutablePointer<Void> 转换为 UInt8?

How do you convert a UnsafeMutablePointer<Void> to UInt8?

问题很简单,就是不知道怎么弄:

如何将 UnsafeMutablePointer 转换为 UInt8?

我试过这样转换它:

UInt8(theUnsafeMutablePointerVar)

但它给了我以下错误:找不到接受类型 'UnsafeMutablePointer'[=12= 的参数列表的类型 'UInt8' 的初始值设定项]

你必须先将指针转换为正确的类型 (指向UInt8的指针)然后你可以访问它指向的内存:

let u8 = UnsafePointer<UInt8>(theUnsafeMutablePointerVar).memory

Swift 3中,一个来自C的空指针被导入到Swift作为 UnsafeMutableRawPointer,可以读取指向的数据

let u8 = theUnsafeMutablePointerVar.load(as: UInt8.self)

使用最新的pointee属性Swift.