我有一个客观的C函数,它给了我一个
UnsafePointer<UInt8>/UnsafePointer<CUnsignedChar>.
但是我需要这些数据作为
UnsafePointer<Int8>
遗憾的是,我要求的功能
UnsafePointer<UInt8>.
答案 0 :(得分:0)
在你的情况下,&#34;不安全的位投射&#34;将是最简单的解决方案:
let ptr: UnsafePointer<UInt8> = ...
let i8ptr = unsafeBitCast(ptr, to: UnsafePointer<Int8>.self)
另一种选择是&#34;记忆重新绑定&#34;:
ptr.withMemoryRebound(to: Int8.self, capacity: <count>) { i8ptr in
// ...
}