4

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

MidDev
  • 182
  • 1
  • 15

1 Answers1

6

you will add @escaping

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

}
SymbolixAU
  • 25,502
  • 4
  • 67
  • 139
user2296278
  • 528
  • 1
  • 4
  • 17