将非转义值转换为 'T' 可能允许它转义 Xcode 10 Swift CGPath
Converting non-escaping value to 'T' may allow it to escape Xcode 10 Swift CGPath
我有这段代码,它在 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))
}
我收到这 2 行代码的错误
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
对于 MemoryLayout 和 unsafeBitCast
您将添加 @escaping
func forEach( body: @escaping @convention(block) (CGPathElement) -> Void) {
}
我有这段代码,它在 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))
}
我收到这 2 行代码的错误
print(MemoryLayout.size(ofValue: body))
let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)
对于 MemoryLayout 和 unsafeBitCast
您将添加 @escaping
func forEach( body: @escaping @convention(block) (CGPathElement) -> Void) {
}