I want to use code from this link which is in swif 2
public protocol SGLImageType {
typealias Element
var width:Int {get}
var height:Int {get}
var channels:Int {get}
var rowsize:Int {get}
func withUnsafeMutableBufferPointer(
@noescape body: (UnsafeMutableBufferPointer<Element>) throws -> Void
) rethrows
}
a class implemented above protocol:
final public class SGLImageRGBA8 : SGLImageType { ... public func withUnsafeMutableBufferPointer(@noescape body: (UnsafeMutableBufferPointer<UInt8>) throws -> Void) rethrows {
try array.withUnsafeMutableBufferPointer(){
// This is unsafe reinterpret cast. Be careful here.
let st = UnsafeMutablePointer<UInt8>($0.baseAddress)
try body(UnsafeMutableBufferPointer<UInt8>(start: st, count: $0.count*channels))
}
}
in swift 3, the line let st = UnsafeMutablePointer<UInt8>($0.baseAddress)
throws this error:
'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type
how to resolve this error?