I have an NSMutableArray
of UIImageViews
which I iterate through continuously (using a CADisplayLink
). I do this to continuously move the UIImageViews
around the screen.
When I remove a UIImageView
from the array, I sometimes get the error:
EXC_BAD_ACCESS (code=1, address=0x20000008)
However I use to get the error "Array was mutated while being enumerated" in the past before I started using ARC/iOS6 so I think these two errors mean exactly the same thing but i'm not sure.
Anyway here is my question. Removing a UIImageView
from the array using any of the following methods gives me the error stated above.
[imageViews removeObject:imageView];
[imageViews performSelector:@selector(removeObject:) withObject:imageView];
[imageViews performSelectorOnMainThread:@selector(removeObject:) withObject:imageView waitUntilDone:YES];
However, using any of the methods below never gives me the error.
[imageViews performSelectorOnMainThread:@selector(removeObject:) withObject:imageView waitUntilDone:NO];
[imageViews performSelector:@selector(removeObject:) withObject:imageView afterDelay:.01];
So can someone explain to me why removing an object from an NSMutableArray
using the first set of methods listed above gives me what I believe is a "Array was mutated while being enumerated" error, while using the second set of methods NEVER gives me that error?
I have been using the second set of methods listed above all the time to get around this error (and everything works perfectly if I use them) but I would like to know exactly why my problem is resolved when I use them and if it is safe to use one of those two methods.
This is my first time posting a question so forgive me if I am posting this the wrong way.