2016-09-18 91 views
1

我試圖將我的項目更新爲swift 3.0,並且在UnsafeMutablePointer中遇到了問題。無法爲類型'UnsafeMutablePointer'<uint8>'使用類型爲'(UnsafeMuatableRawpointer?)'的參數列表調用初始值設定項'

這裏是我的錯誤

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 

爲什麼呢?如何解決它?

回答

3

從空指針(又名UnsafeMutableRawPointer)將在斯威夫特3.改變你有2種選擇:

如果你知道你的緩衝區長度(更安全):

let dataBuffer = src_buff?.bindMemory(to: UInt8.self, capacity: len) 

如果你不知道它:

let dataBuffer = src_buff?.assumingMemoryBound(to: UInt8.self) 
+0

thx !!!有效! –

相關問題