Hi, I'm having trouble figuring out a replacement for this code. I thought it was working, but it is erroring now because I'm modifying self while enumerating through it. Any ideas?
Thanks in advance.
- (void)removeAllSquares { for (Square *square in self) { if ([square isKindOfClass:[Square class]]) { [self removeChild:square]; } } }
Also, here is the error I get...
2011-03-09 19:30:26.047 Squares[710:207] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <Play: 0x5bedf90> was mutated while being enumerated.<Play: 0x5bedf90>' *** Call stack at first throw: ( 0 CoreFoundation 0x01343be9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x014985c2 objc_exception_throw + 47 2 CoreFoundation 0x013436a9 __NSFastEnumerationMutationHandler + 377 3 Squares 0x000050c4 -[Play removeAllSquares] + 159 4 Squares 0x000051cf -[Play gameOverForReason:] + 36 5 Squares 0x000080b7 -[Square bombTimerDone:] + 114 6 CoreFoundation 0x012b467d __invoking___ + 29 7 CoreFoundation 0x012b4551 -[NSInvocation invoke] + 145 8 Squares 0x0001f67f -[SPEventDispatcher dispatchEvent:] + 593 9 Squares 0x0002391f -[SPTween advanceTime:] + 2780 10 Squares 0x00024727 -[SPJuggler advanceTime:] + 347 11 Squares 0x00017e09 -[SPStage advanceTime:] + 76 12 Squares 0x00020e4e -[SPView renderStage] + 214 13 QuartzCore 0x00dee6a8 _ZN2CA7Display11DisplayLink8dispatchEyy + 128 14 QuartzCore 0x00dee7ed _ZN2CA7Display19EmulatorDisplayLink8callbackEP16__CFRunLoopTimerPv + 145 15 CoreFoundation 0x01324fe3 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 19 16 CoreFoundation 0x01326594 __CFRunLoopDoTimer + 1220 17 CoreFoundation 0x01282cc9 __CFRunLoopRun + 1817 18 CoreFoundation 0x01282240 CFRunLoopRunSpecific + 208 19 CoreFoundation 0x01282161 CFRunLoopRunInMode + 97 20 GraphicsServices 0x01bfc268 GSEventRunModal + 217 21 GraphicsServices 0x01bfc32d GSEventRun + 115 22 UIKit 0x0033442e UIApplicationMain + 1160 23 Squares 0x00002796 main + 104 24 Squares 0x00002725 start + 53 ) terminate called after throwing an instance of 'NSException'