Why not use removeAllObjects instead of the Fast Enumeration


On page 245 we’re updating touchesCancelled:withEvent: to remove all lines in progress, since we’ve been interrupted by the OS. To clear the array we have:

for (UITouch *t in touches) { NSValue *key = [NSValue valueWithNonretainedObject:t]; [self.linesInProgress removeObjectForKey:key]; }
Instead, why not use this line:

[self.linesInProgress removeAllObjects];
Both compiled and seemed to work okay, but I wasn’t successful locating a way to simulate an interruption. Using removeAllObjects seems to be more clear from a reader’s perspective, no?


Sounds reasonable to me. :slight_smile:

Incidentally, it’s actually pretty easy to simulate an interruption in the simulator.

Just drag up from near the bottom, or down from near the top. The app initially sees the drag (so it draws red), but then the OS takes over and decides the touch was really for the Control Center (from the bottom) or for the Notification Center (from the top).