remove all subLayers from a view
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() }
Swift 3.0 & Swift 4.0
Set the sublayers
property to nil
to remove all sublayers from a view.
view.layer.sublayers = nil
also you can add
.removeAll()