I have the following code:
for (NSImageView *image in self.view.subviews) {
if (image.frame.size.height == 67 && image.frame.size.width == 46) {
[image removeFromSuperview];
}
}
This is called when a button is pressed. I want each NSImageView that has those dimensions to be removed. The problem is, it removes one only. I have to keep clicking the button over and over to clear the images. There is 4 of them.
However, I noticed that the log it produces shows the very last line getting removed each time. I’m guessing because these images are the top-most layers.
So my question is, how can I make it so each NSImageViews with a height of 67 and width of 46 are removed from the view at once?
Thank you!
The mutating array error should prevent your code from executing. Use this instead: