Maybe I'm the first person doing this in Swift but there seems to be nothing on the net using &/inout together with uint8_t in Swift. Could someone translate this please? Is this relationship bitwise?
Objective-C
uint8_t *buf=(uint8_t *) CVPixelBufferGetBaseAddress(cvimgRef);
Swift attempt
let inout buf:uint8_t = SOMETHING HERE CVPixelBufferGetBaseAddress(cvimgRef)
CVPixelBufferGetBaseAddress()
returns a UnsafeMutablePointer<Void>
,
which can be converted to an UInt8
pointer via
let buf = UnsafeMutablePointer<UInt8>(CVPixelBufferGetBaseAddress(pixelBuffer))
Update for Swift 3 (Xcode 8), Checked for Swift 5 (Xcode 11):
if let baseAddress = CVPixelBufferGetBaseAddress(pixelBuffer) {
let buf = baseAddress.assumingMemoryBound(to: UInt8.self)
// `buf` is `UnsafeMutablePointer<UInt8>`
} else {
// `baseAddress` is `nil`
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With