• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Updating tracking areas Rect
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Updating tracking areas Rect
      • From: Graham Cox <email@hidden>
References: 
 >Updating tracking areas Rect (From: Gustavo Pizano <email@hidden>)
 >Re: Updating tracking areas Rect (From: Gustavo Pizano <email@hidden>)
 >Re: Updating tracking areas Rect (From: Joar Wingfors <email@hidden>)
 >Re: Updating tracking areas Rect (From: Graham Cox <email@hidden>)

  • Prev by Date: Trying to do something that *should* be simple...
  • Next by Date: Re: Updating tracking areas Rect
  • Previous by thread: Re: Updating tracking areas Rect
  • Next by thread: Re: Updating tracking areas Rect
  • Index(es):
    • Date
    • Thread