我正在为 UIBezierPath 使用以下扩展:
extension UIBezierPath {
var elements: [PathElement] {
var pathElements = [PathElement]()
withUnsafeMutablePointer(&pathElements) { elementsPointer in
CGPathApply(CGPath, elementsPointer) { (userInfo, nextElementPointer) in
let nextElement = PathElement(element: nextElementPointer.memory)
let elementsPointer = UnsafeMutablePointer<[PathElement]>(userInfo)
elementsPointer.memory.append(nextElement)
}
}
return pathElements
}
}
这是来自网站:
但是,这与 Swift 3 中断了以下行:
let elementsPointer = UnsafeMutablePointer<[PathElement]>(userInfo)
显示以下错误:
Cannot invade initializer for type 'UnsafeMutablePointer<[PathElement]>' with an argument list of type '(UnsafeMutableRawPointer?)'
我知道这与 Swift 3 的变化有关:UnsafeRawPointerMigration
但是,我不太确定将其移植到 Swift 3 的最佳方法。您能否在这方面提供一些帮助,并为上述扩展提供更新代码?