In an animation I added a lot of sublayers to a view, with:
[self.view.layer addSublayer:layer1];
[self.view.layer addSublayer:
The sublayers
property of a CALayer
object returns a copy of the array. Setting it no nil does nothing about the sublayers. This however will do:
for (CALayer *layer in self.view.layer.sublayers) {
[layer removeFromSuperlayer];
}
Or, in Swift
self.view.layer.sublayers?.forEach { $0.removeFromSuperlayer() }