Created
December 28, 2016 14:29
-
-
Save kristopherjohnson/e91155af9e2e20b53053edec99e6eddf to your computer and use it in GitHub Desktop.
A Swift-friendly wrapper for CGPath.apply()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See http://www.openradar.me/radar?id=5065840256876544 for explanation of why this wrapper is desirable.