Re: Updating tracking areas Rect
Re: Updating tracking areas Rect
- Subject: Re: Updating tracking areas Rect
- From: "Henry McGilton (Boulevardier)" <email@hidden>
- Date: Mon, 28 Dec 2009 18:03:13 -0800
On Dec 28, 2009, at 3:27 PM, Graham Cox wrote:
>
> 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?)
Yes, fast enumeration specifically states:
Enumeration is “safe”—the enumerator has a mutation guard so that if you attempt to modify the collection during enumeration, an exception is raised.
And also:
Since mutation of the object during iteration is forbidden, you can perform multiple enumerations concurrently.
>
> 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.
>
Cheers,
. . . . . . . . Henry
=================================================
iPhone App Development and Developer Education . . .
Visit www.nonatomic-retain.com
Mac OSX Application Development, Plus a Great Deal More . . .
Visit www.trilithon.com
_______________________________________________
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