Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
How to print out a CGPathRef for debugging purposes
static void outputApplier(void* info, const CGPathElement* element)
{
NSMutableArray* a = (NSMutableArray*) info;
int nPoints;
NSString * pathElementType = nil;
switch (element->type)
{
case kCGPathElementMoveToPoint:
nPoints = 1;
pathElementType = @"kCGPathElementMoveToPoint";
break;
case kCGPathElementAddLineToPoint:
nPoints = 1;
pathElementType = @"kCGPathElementAddLineToPoint";
break;
case kCGPathElementAddQuadCurveToPoint:
nPoints = 2;
pathElementType = @"kCGPathElementAddQuadCurveToPoint";
break;
case kCGPathElementAddCurveToPoint:
nPoints = 3;
pathElementType = @"kCGPathElementAddCurveToPoint";
break;
case kCGPathElementCloseSubpath:
nPoints = 0;
pathElementType = @"kCGPathElementCloseSubpath";
break;
default:
nPoints = 0;
pathElementType = @"unknown path element type";
return;
}
NSMutableString * pointsList = [NSMutableString new];
for (int i = 0; i < nPoints; i++)
{
[pointsList appendFormat:@" (%@)", NSStringFromCGPoint(element->points[i])];
}
NSLog(@"%@ : %@", pathElementType, pointsList);
}
...
CGPathRef somePath = ...;
CGPathApply(somePath, NULL, outputApplier);
@DanSkeel

This comment has been minimized.

Copy link

commented Jul 25, 2016

Thanks. BTW you may find it useful, console command does similar out of the box p (void)CGPathPrint(pathRef, 0). Found in NSHipster Blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.