• 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: NSEnumerator and the missing peek method
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSEnumerator and the missing peek method


  • Subject: Re: NSEnumerator and the missing peek method
  • From: Jan Vereecken <email@hidden>
  • Date: Thu, 29 Sep 2005 23:27:46 +0200


On 29 Sep 2005, at 23:01, Nick Zitzmann wrote:


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


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


NSEnumerator isn't in the AppKit.


- How do other developers conquer this problem?


If you need to know what the next object is going to be, then you probably shouldn't use NSEnumerator. Instead, use an array iterator, like this: (warning - code written in Mail, untested, use at your own risk, etc.)


unsigned int i;
const unsigned int count = [array count];

for (i = 0 ; i < count ; i++)
{
    id object = [array objectAtIndex:i];

    // and so on, and so on...
    if (i+1 < count)
    {
        // peek at the next object here
    }
}


That is the solution I use at the moment. I was only wondering if someone maybe found a way to extend NSEnumerator with a new method to peek which would make following code possible.


while(myObject = [enumerator nextObject]) {
    do something (for example append a string)
    if([enumerator hasNext]) {
        do something (for example add a newline)
    }
}

Java offers this functionality in their Iterator's and I was wondering if the same was possible in Cocoa.

Nick Zitzmann
<http://www.chronosnet.com/>




_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: NSEnumerator and the missing peek method
      • From: Marcel Weiher <email@hidden>
    • Re: NSEnumerator and the missing peek method
      • From: Nick Zitzmann <email@hidden>
References: 
 >NSEnumerator and the missing peek method (From: Jan Vereecken <email@hidden>)
 >Re: NSEnumerator and the missing peek method (From: Nick Zitzmann <email@hidden>)

  • Prev by Date: Re: Background if Login Item launched
  • Next by Date: 2 problems with NSOutlineView
  • Previous by thread: Re: NSEnumerator and the missing peek method
  • Next by thread: Re: NSEnumerator and the missing peek method
  • Index(es):
    • Date
    • Thread