• 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: 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

  • Follow-Ups:
    • Re: Updating tracking areas Rect
      • From: "Henry McGilton (Boulevardier)" <email@hidden>
    • 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>)

  • Prev by Date: Re: Shared CoreData DataModel and DB file..
  • Next by Date: To-Many/To-Many Master/Detail Core Data / Bindings Question
  • Previous by thread: Re: Updating tracking areas Rect
  • Next by thread: Re: Updating tracking areas Rect
  • Index(es):
    • Date
    • Thread