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 protected])
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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]