• 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: File Extensions Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: File Extensions Problem


  • Subject: Re: File Extensions Problem
  • From: Andrew Merenbach <email@hidden>
  • Date: Fri, 22 Aug 2008 08:39:59 -0700

On Aug 22, 2008, at 8:23 AM, Michael Ash wrote:

On Fri, Aug 22, 2008 at 6:23 AM, Graham Cox <email@hidden> wrote:
-reverseObjectEnumerator is no different, because it "lets you access each
object in the receiver, in order, from the element at the highest index down
to the element at index 0". This statement will hold true for any future
implementation of NSMutableArray, meaning that it is now, and always will be
safe to delete items in the array at or higher than the current index. By
the definition of an array, removing an item only affects the indexes of
objects with equal or greater indexes than the removed item.

You are making a big, unwarranted assumption about how reverseObjectEnumerator works. Namely, you are assuming that it merely tracks an index, and uses -objectAtIndex: (or equivalent) to retrieve each object.

What if the enumerator actually just keeps a pointer to the array's
internal storage? This would be perfectly allowed by the API. But
then, as you delete things, the array may decide to reallocate its
internal storage, leaving the enumerator's pointer to dangle, and
causing you to crash.

Do not modify collections while you enumerate them. You're not allowed
to. Just because it seems like maybe you ought to be allowed in this
one special case doesn't make it so.

If you really want to enumerate backwards while deleting items at the
tail end of the array, write a manual for loop that calls
-objectAtIndex: each time. This is guaranteed to work.

Mike

To build on this, doesn't fast enumeration (Leopard-only, of course) raise an exception if a value is modified while the enumeration is running? (Not tested personally by me, but building upon an earlier thread from a little while back.)


Cheers,
	Andrew

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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: File Extensions Problem
      • From: Charles Srstka <email@hidden>
    • Re: File Extensions Problem
      • From: "Sherm Pendley" <email@hidden>
References: 
 >File Extensions Problem (From: Adil Saleem <email@hidden>)
 >Re: File Extensions Problem (From: Michael Dautermann <email@hidden>)
 >Re: File Extensions Problem (From: Andrew Merenbach <email@hidden>)
 >Re: File Extensions Problem (From: Graham Cox <email@hidden>)
 >Re: File Extensions Problem (From: Phil <email@hidden>)
 >Re: File Extensions Problem (From: Graham Cox <email@hidden>)
 >Re: File Extensions Problem (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: File Extensions Problem
  • Next by Date: Re: Object change to NSView update
  • Previous by thread: Re: File Extensions Problem
  • Next by thread: Re: File Extensions Problem
  • Index(es):
    • Date
    • Thread