365Cocoa

A snippet of Objective-C code per day, 365 days long.
Written by Pieter Omvlee, developer and owner of Bohemian Coding.

May 8

Day 49: Tail follow-up

On Day 47 I posted a snippet with the -tail method and a question was asked in what situation I found this useful. I thought it’d be a nice opportunity to post an example of how I use -tail in Sketch.

This abbreviated snippet of code makes a boolean operation over multiple bezier paths. I already have the code to do an operation on two shapes and using it on more than two shapes is achieved by accumulating the result. Note that the layers variable that is used just holds the layers on which to do a boolean operation.

  NSBezierPath *accumulatedPath = [[layers firstObject] bezierPath];
  for (MSShapeLayer *shape in [layers tail])
    accumulatedPath = [accumulatedPath booleanOp:operation
                                        withPath:[shape bezierPath]];