1
我想從this link 這是在SWIF使用代碼2如何將array.withUnsafeMutableBufferPointer從swift 2遷移到swift 3?
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
}
上述方案實現的類:
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))
}
}
在迅速3
,線let st = UnsafeMutablePointer<UInt8>($0.baseAddress)
引發此錯誤:
'init' is unavailable: use 'withMemoryRebound(to:capacity:_)' to temporarily view memory as another layout-compatible type
如何解決此錯誤?
可能重複[Swift 3 UnsafePointer($ 0)不再在Xcode 8 beta 6中編譯](http://stackoverflow.com/questions/39046377/swift-3-unsafepointer0-no-longer-compile-in-xcode -8-beta-6) – kennytm
@kennytm其不重複的。 – xaled