I am doing some advanced drawing in my NSView subclass using CALayers using -(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx In this callback I am given a CALayer, but I need to know the z-index of that layer in an arbitrarily large list of layers (all of which are sublayers of the root layer).
I tried int index = [self.layer.sublayers indexOfObject:someCALayer]; but this does not seem to work.
How can I determine the index of a CALayer?
I ended up setting the z-index property of each CALayer as I added them, and used that to determine position.