我试图将我的项目更新为swift 3.0,并且我在UnsafeMutablePointer中遇到了麻烦。
这是我的错误
Cannot invoke initializer for type 'UnsafeMutablePointer<uint8>' with an argument list of type '(UnsafeMuatableRawpointer?)'
代码:
let imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer)
let src_buff = CVPixelBufferGetBaseAddress(imageBuffer!)
let dataBuffer = UnsafeMutablePointer<UInt8>(src_buff) //error here
为什么呢?如何解决?
答案 0 :(得分:3)
在Swift 3中,从void指针(又名UnsafeMutableRawPointer
)转换已更改。您有2个选项:
如果您知道缓冲区长度(更安全):
let dataBuffer = src_buff?.bindMemory(to: UInt8.self, capacity: len)
如果您不知道:
let dataBuffer = src_buff?.assumingMemoryBound(to: UInt8.self)