I have an NSMutableArray
that stores mousejoints for a Box2d physics simulation. When using more than one finger to play I'll get exceptions stating
NSArray was mutated while being enumerated
I know this is because I'm deleting objects from the array while also enumerating through it, invalidating the enum.
What I want to know is what is the best strategy to solve this going forward? I've seen a few solutions online: @synchronized
, copying the array before enumerating or putting the touch joint into a garbage array for later deletion (which I'm not sure would work, because I need to remove the mousejoint from the array straight after removing it from the world).