• 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: Why add a nil item to an NSArray ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why add a nil item to an NSArray ?


  • Subject: Re: Why add a nil item to an NSArray ?
  • From: Bill Bumgarner <email@hidden>
  • Date: Mon, 27 Jun 2005 15:31:41 -0700

On Jun 27, 2005, at 3:20 PM, Mark Munz (DevList) wrote:
It is non-intuitive. Is this maybe something left over from the past?

No. It is the only way to implement support for variadic arguments.

The variable argument method already has process a variable list of arguments already and can easily determine when the end is reached.

Only because something in the argument list gives an indication as to when the end has been reached. There is no way to know at runtime when the end of the argument list has been reached via any other means that contextual information.


Other methods like [NSString stringWithFormat:(NSString*)format,...]
work as you would expect.

But NSArray and NSDictionary are very unhappy campers if you don't end your definitions with a nil.

NSString works "as you would expect" because the format string provides the contextual information to know exactly what type and how many arguments follow the format string. If you do:


    [NSString stringWithFormat: @"%c %s %d", 5]

+stringWithFormat: will be just as unhappy not passing nil at the end of the parameter list to NSDictionary/NSArray.

The 'nil' is passed to terminate the variable list of objects passed.

You might find this useful:

http://www.cocoabuilder.com/archive/message/cocoa/2005/1/8/125344

b.bum
_______________________________________________
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: 
 >Why add a nil item to an NSArray ? (From: Martin Ottenwaelter <email@hidden>)
 >Re: Why add a nil item to an NSArray ? (From: SA Dev <email@hidden>)
 >Re: Why add a nil item to an NSArray ? (From: "Mark Munz (DevList)" <email@hidden>)

  • Prev by Date: Re: Why add a nil item to an NSArray ?
  • Next by Date: Re: Why add a nil item to an NSArray ?
  • Previous by thread: Re: Why add a nil item to an NSArray ?
  • Next by thread: Re: Why add a nil item to an NSArray ?
  • Index(es):
    • Date
    • Thread