Re: Updating tracking areas Rect
Re: Updating tracking areas Rect
- Subject: Re: Updating tracking areas Rect
- From: Graham Cox <email@hidden>
- Date: Tue, 29 Dec 2009 10:27:23 +1100
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 (email@hidden)
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:
This email sent to email@hidden