也许我是Swift中第一个这样做的人,但在Swift中使用&/ inout和uint8_t似乎在网上没有任何东西。有人可以翻译一下吗?这种关系是按位的吗?
目标C
uint8_t *buf=(uint8_t *) CVPixelBufferGetBaseAddress(cvimgRef);
快速尝试
let inout buf:uint8_t = SOMETHING HERE CVPixelBufferGetBaseAddress(cvimgRef)
CVPixelBufferGetBaseAddress()返回一个UnsafeMutablePointer<Void>,可以通过将其转换为UInt8指针
CVPixelBufferGetBaseAddress()
UnsafeMutablePointer<Void>
UInt8
let buf = UnsafeMutablePointer<UInt8>(CVPixelBufferGetBaseAddress(pixelBuffer))
Swift 3(Xcode 8)的更新,Swift 5(Xcode 11)的检查:
if let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer) { let buf = baseAddress.assumingMemoryBound(to: UInt8.self) // `buf` is `UnsafeMutablePointer<UInt8>` } else { // `baseAddress` is `nil` }