title: How to fix convenience init w/closure Extension of NSBezierPath to use CGPath that fails in Swift 5.0?
body: <p>Inline below is is a method I acquired somewhere for extending <code>NSBezierPath</code> using a convenience initializer that takes <code>CGPath</code> as an argument so that it behaves more like <code>UIBezierPath</code> on iOS.</p>
  
  <p>It worked previously, but when I try to compile it (years later) on Swift 5, I get the the following compile time error:</p>
  
  <p><strong><em>A C function pointer cannot be formed by a closure that captures context</em></strong>  </p>
  
  <p>How can I resolve that?</p>
  
  <pre><code>convenience init(path : CGPath) {
      path.apply(info: nil, function: { (_, elementPointer) in
          let element = elementPointer.pointee
          switch element.type {
          case .moveToPoint:
              let points = Array(UnsafeBufferPointer(start: element.points, count: 1))
              self.move(to: points[0])
              break
          case .addLineToPoint:
              let points = Array(UnsafeBufferPointer(start: element.points, count: 1))
              self.line(to: points[0])
              break
          case .addQuadCurveToPoint:
              let points = Array(UnsafeBufferPointer(start: element.points, count: 2))
              let qp0 = self.currentPoint
              let qp1 = points[0]
              let qp2 = points[1]
              let m = CGFloat(2.0 / 3.0)
              var cp1 = NSPoint()
              var cp2 = NSPoint()
              cp1.x = (qp0.x + ((qp1.x - qp0.x) * m))
              cp1.y = (qp0.y + ((qp1.y - qp0.y) * m))
              cp2.x = (qp2.x + ((qp1.x - qp2.x) * m))
              cp2.y = (qp2.y + ((qp1.y - qp2.y) * m))
              self.curve(to: qp2, controlPoint1:cp1, controlPoint2:cp2)
          case .addCurveToPoint:
              let points = Array(UnsafeBufferPointer(start: element.points, count: 3))
              self.curve(to:points[2], controlPoint1:points[0], controlPoint2:points[1])
              break
          case .closeSubpath:
              self.close()
          @unknown default:
              break;
          }
      })
  }
  </code></pre>