UnsafeMutablePointer Warning with Swift 5

前端 未结 3 1349
眼角桃花
眼角桃花 2020-12-06 23:34

I had this:

let alphaPtr = UnsafeMutablePointer(mutating: alpha) as UnsafeMutablePointer?

W

3条回答
  •  时光说笑
    2020-12-06 23:41

    Do you need use the withUnsafeBufferPointer method from Array as

    var alphaPtr: UnsafeBufferPointer = alpha.withUnsafeBufferPointer { $0 }
    

    that's command produce a pointer optional if you need working with a specific type could you you use bindMemory(to:) or other function that match with you requirements.

    Sometimes use a &alpha if you need a UnsafeRawPointer as a function parameter.

提交回复
热议问题