Skip to content

Instantly share code, notes, and snippets.

@kristopherjohnson
Created December 28, 2016 14:29
Show Gist options
  • Save kristopherjohnson/e91155af9e2e20b53053edec99e6eddf to your computer and use it in GitHub Desktop.
Save kristopherjohnson/e91155af9e2e20b53053edec99e6eddf to your computer and use it in GitHub Desktop.
A Swift-friendly wrapper for CGPath.apply()
import CoreGraphics
extension CGPath {
/// Call the given closure on each element of the path.
func forEach(_ body: @escaping (CGPathElement) -> Void) {
var info = body
self.apply(info: &info) { (infoPtr, elementPtr) in
let opaquePtr = OpaquePointer(infoPtr!)
let body = UnsafeMutablePointer<(CGPathElement) -> Void>(opaquePtr).pointee
body(elementPtr.pointee)
}
}
}
@kristopherjohnson
Copy link
Author

kristopherjohnson commented Dec 28, 2016

See http://www.openradar.me/radar?id=5065840256876544 for explanation of why this wrapper is desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment