【问题标题】:Converting non-escaping value to 'T' may allow it to escape Xcode 10 Swift CGPath将非转义值转换为“T”可能允许它转义 Xcode 10 Swift CGPath
【发布时间】:2019-02-19 14:23:59
【问题描述】:

我有这段代码,它在 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)

对于 MemoryLayoutunsafeBitCast

【问题讨论】:

    标签: swift4 cgpath xcode10 ios12


    【解决方案1】:

    你将添加 @escaping

    func forEach( body: @escaping @convention(block) (CGPathElement) -> Void) {
    
    }
    

    【讨论】:

      猜你喜欢
      • 2019-01-05
      • 2021-02-03
      • 2020-02-04
      • 2017-07-02
      • 2016-12-23
      • 2014-12-07
      • 2019-02-24
      • 1970-01-01
      • 2014-08-16
      相关资源
      最近更新 更多