我有这段代码,它在 Xcode 9 中运行良好,但在 Xcode 10 中我收到了这个错误。将非转义值转换为 'T' 可能允许它转义
这是代码:
extension CGPath {
func forEach( body: @convention(block) (CGPathElement) -> Void) {
typealias Body = @convention(block) (CGPathElement) -> Void
let callback: @convention(c) (UnsafeMutableRawPointer, UnsafePointer<CGPathElement>) -> Void = { (info, element) in
let body = unsafeBitCast(info, to: Body.self)
body(element.pointee)
}
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
self.apply(info: unsafeBody, function: unsafeBitCast(callback, to: CGPathApplierFunction.self))
}
Run Code Online (Sandbox Code Playgroud)
我收到此 2 行代码的错误
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
Run Code Online (Sandbox Code Playgroud)
用于MemoryLayout和unsafeBitCast