Search code examples
cocoa-touchswift3

Convert UnsafeMutableRawPointer to UnsafeMutablePointer<T> in swift 3


I have this code

let grayData = UnsafeMutablePointer<UInt8>(other: malloc(width * height * sizeof(UInt8)))

Which doesn't compile in Swift 3. How do I fix this?


Solution

  • In your case, you'd better use allocate(capacity:) method.

    let grayData = UnsafeMutablePointer<UInt8>.allocate(capacity: width * height)