【发布时间】:2017-04-14 15:35:48
【问题描述】:
我想使用来自this link 的代码 在 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
}
上面协议实现的类:
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))
}
}
在 swift 3 中,let st = UnsafeMutablePointer<UInt8>($0.baseAddress) 行抛出此错误:
'init' 不可用:使用 'withMemoryRebound(to:capacity:_)' 暂时将内存视为另一种布局兼容的类型
如何解决这个错误?
【问题讨论】:
-
@kennytm 它不是重复的。