• 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: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)


  • Subject: Re: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
  • From: "Michael Ash" <email@hidden>
  • Date: Sun, 16 Jul 2006 15:48:29 -0400

On 7/16/06, Prachi Gauriar <email@hidden> wrote:

Also, using an enumerator with an array is actually less efficient (and harder to understand, IMO) than just using a for loop like:

unsigned ttyCount = [ttysArray count];
for (unsigned i = 0; i < ttyCount; i++) {
     [ttyPopUpButton addItemWithTitle:[ttysArray objectAtIndex:i]];
}

First, efficiency doesn't really matter most of the time. Write what's easiest to understand, then optimize where it's important, and always optimize later.

Second, this is not the case in my tests on large arrays. The for loop
approach was 10-20% slower than NSEnumerator. Details are here:

http://www.cocoadev.com/index.pl?NSEnumeratorSpeed

Whether it's easier to understand is basically personal taste. I think
enumerators are nicer (in particular, they can let you switch data
structures without changing code), but I've seen a lot of really
terrible newbieisms related to keeping track of a location in an array
by using a stored NSEnumerator instead of a simple index. In any case,
knowing the alternatives is a good thing.

Mike
_______________________________________________
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


References: 
 >Re: NSPipe / NSTask ls -> Array (From: Prachi Gauriar <email@hidden>)
 >Re: NSPipe / NSTask ls -> Array (From: Shawn Erickson <email@hidden>)
 >Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array) (From: Prachi Gauriar <email@hidden>)

  • Prev by Date: Re: Key Value coding with Slider vs TextField
  • Next by Date: Re: NSTreeOutline display glitches; how to troubleshoot?
  • Previous by thread: Re: NSEnumerator -> NSPopupButton (was: Re: NSPipe / NSTask ls -> Array)
  • Next by thread: Re: NSPipe / NSTask ls -> Array
  • Index(es):
    • Date
    • Thread