• 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: Joar Wingfors <email@hidden>
  • Date: Mon, 28 Dec 2009 19:30:20 -0800

On 28 dec 2009, at 18.41, Graham Cox wrote:

> So, if -trackingAreas returns the actual array (rather than a copy), and -removeTrackingArea: is basically a wrapper for -removeObject: on that same array then the loop will fail with this exception. Since we don't know if either of these things are true, then the loop as written will either fail, or depend upon implementation details which could change for its success.


Fair enough. Since the behavior isn't documented, it would be safer to use:

	for (NSTrackingArea *trackingArea in [[[self trackingAreas] copy] autorelease]) {
		[self removeTrackingArea:trackingArea];
	}

I've filed <rdar://problem/7500948> to see if updated documentation would be in order.


> However that's a different problem from the one I mentioned, where a forward iteration of an array that removes the indexed item will end up skipping every other object. Iterating a copy of the array will avoid that, so I was wondering if fast enumeration operated on a copy internally. I'm thinking 'no', since a) it wouldn't be so fast, b) there would be no need for the exception you mention and c) there are plenty of cases where a copy is undesirable or unnecessary.
>
> So however you look at it, the suggested replacement for the original faulty loop is just as faulty.


"However you look at it"? It's *only* faulty if the "trackingAreas" accessor returns the internal array (it doesn't, by the way).


j o a r


_______________________________________________

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

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

  • Prev by Date: Re: Updating tracking areas Rect
  • 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