Is there way to select object by their specific tag without the use of a loop?
So instead:
for (UIImageView *someObject in [self.view subviews]) {
if (someObject.tag == someInteger) {
[someObject removeFromSuperview];
}
}
Use something with a more direct approach like:
[[UIImageView.whereTagEquals someInteger] removeFromSuperview];
Although I think if there was such an option it would work the same way. It would loop “behind the scene” all the UIImageViews and do something if it found the right one.
Or maybe someone can help me get the same desired result with a different approach. I notice that because of too much loops my game starts to slow down at a certain point.
Thank you!
A one liner you can use is
-[UIView viewWithTag:], but this will likely loop internally as well. A faster approach for lots of views is to use anNSDictionary(NSNumberinstances as keys plus views as values). Dictionaries use hashes internally so they’re faster in most cases.