On Fri, Aug 22, 2008 at 10:23 PM, Graham Cox <[EMAIL PROTECTED]> wrote:
> You shouldn't go modifying the array in general, for sure. But the special
> case of modification by deleting the last item in the array is safe, and
> always will be. In fact deleting any item with a higher index than current
> is safe, and always will be. Why? Because an ordinary for loop that counts
> down is free to do this and the existence of such loops in shipped code
> means that NSMutableArray can never be changed in such a way as to break
> code like that. (It's also hard to see how it could be, even theoretically).
>

Although an NSEnumerator is analogous to a for loop using an index
variable, that doesn't make the contract on them the same.
NSMutableArray can't be changed to break the traditional for loop that
modifies the array, but the NSEnumerator returned by NSMutableArray
can be.

You're making an assumption about the implementation of how the
enumerator moves through the list; and although I think this is a sane
assumption (any other way of enumerating through the list would be
strange), you're still breaking the contract of NSEnumerator. There is
no documented exception about the objects that have already been
enumerated over, so it shouldn't be assumed that there is one.

Phil
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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]

Reply via email to