On 29/12/2009, at 4:00 AM, Joar Wingfors wrote:

>>      NSInteger i = 0;
>>      while ([[self trackingAreas] count]==0) {
>>              [self removeTrackingArea:[[self trackingAreas] 
>> objectAtIndex:i]];
>>              i++;
>>      }
> 
> 
> That loop seems all kinds of wrong...   ;-)
> 
> How about:
> 
>       for (NSTrackingArea *trackingArea in [self trackingAreas]) {
>               [self removeTrackingArea:trackingArea];
>       }


Wouldn't this fall foul of the usual problem with deleting items from the 
collection being iterated, in that it will skip every other object? (Or perhaps 
fast enumeration has a built-in protection against that?)

The first loop is also wrong in that its terminating condition is backwards 
(should be >0) as well as having the skip every other object problem. If you 
want to remove items from the collection being iterated, you should copy the 
collection temporarily and iterate that or iterate it by index backwards.

--Graham

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to