Making UIBezierPath more like NSBezierPath with elementCount and elementAtIndex Making UIBezierPath more like NSBezierPath with elementCount and elementAtIndex ios ios

Making UIBezierPath more like NSBezierPath with elementCount and elementAtIndex


I made a port on https://github.com/seivan/UIBezierPathPort but it's with Swift.Has a test suite and documentation.Works as of Beta 5.

Technically you should be able to use Swift on a Obj-C project.

Let me know how you like it.


I've bumped into the same problem a couple of months ago and couldn't find anything readily available back then. (Truth be told, since going the CGPathApply route wasn't that bad for my needs, I didn't look very hard to be honest).

The applier function is called for every CGPathElement in the CGPath, such an element consists of a CGPathElementType and a C-array of CGPoints.

Since a CGPathElementType is an enum with only five different values

enum CGPathElementType {   kCGPathElementMoveToPoint,   kCGPathElementAddLineToPoint,   kCGPathElementAddQuadCurveToPoint,   kCGPathElementAddCurveToPoint,   kCGPathElementCloseSubpath};

You don't need to write that much code to do (control)point manipulation / inspection of a path. Having the same interface available would've been nice though.