1. let context = CGContext(...)
2. context.draw(...)
3. let buffer = UnsafeMutablePointer<UInt32>(context.data) // error here
使用Swift 3,第3行会产生一个错误:
Cannot invoke initializer for type 'UnsafeMutablePointer<UInt32>' with an argument list of type '(UnsafeMutableRawPointer?)'
有没有办法将UnsafeMutableRawPointer
转换为UnsafeMutablePointer
在初始化时作为参数接受的任何适当类型?
顺便说一句,UnsafeMutablePointer
的类引用可以找到here。
答案 0 :(得分:0)
我想这会进行初始化。
let ptr = context.data
let data = ptr!.assumingMemoryBound(to: UnsafeMutablePointer<UInt32>.self).pointee
let pixelBuffer = UnsafeMutablePointer<UInt32>(data)