Search code examples
swift4cgpathxcode10ios12

Converting non-escaping value to 'T' may allow it to escape Xcode 10 Swift CGPath


I have this code it was work well in Xcode 9 but in Xcode 10 I received this error. Converting non-escaping value to 'T' may allow it to escape

here is code :

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))
    }

I received this error for this 2 line codes

 print(MemoryLayout.size(ofValue: body))
            let unsafeBody = unsafeBitCast(body, to: UnsafeMutableRawPointer.self)

for MemoryLayout and unsafeBitCast


Solution

  • you will add @escaping

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