Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSEnumerator and the missing peek method




On Sep 29, 2005, at 1:53 PM, Jan Vereecken wrote:

Hello,

I'm currently busy with a project where I regularly make use of a NSEnumerator object to iterate over a set of objects. The "problem" I'm experiencing is that there is no method to peek at the next object (for example [enumerator hasNext]). I circumvent the need to peek via the enumerator with counting the objects of the enumerator ([[enumerator allObjects] count]) and check when the last element is reached (and do something).

Bad idea. -allObjects will create a new array.

- Why didn't the AppKit developers include this (the hasNext method) in the first place?

Probably because you can't always tell if there is a next object until you try to obtain it. Remember, enumerators don't only traverse arrays. They might be going through sets, and I could write an enumerator that traverses a tree, which still behaves the same as all other enumerators


-jcr


John C. Randolph <email@hidden> (408) 914-0013 Roaming Cocoa Engineer, Available for your projects at great Expense and Inconvenience.



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSEnumerator and the missing peek method (From: Jan Vereecken <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.