• 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 Cheeseman <email@hidden>
  • Date: Mon, 27 Jun 2005 17:42:34 -0400

on 2005-06-27 3:23 PM, Dave Hersey at email@hidden wrote:

> Because... That's the spec for the method.
>
>> - (id)initWithObjects:(id)anObject...
>> Initializes a newly allocated set with members taken from the specified list
>> of objects. initWithObjects: takes a comma-separated list of objects
>> terminated by nil...

Among other things, this is a trap for the unwary. When you construct an
array as specified, but one of the objects in the list before the explicit
nil happens to be nil at run time, the array constructor will dutifully
terminate construction of the array, possibly omitting objects after it in
the list. If any item in the list can be nil at run time, you must guard
against this.

--

Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com

PreFab Software - http://www.prefab.com/scripting.html
The AppleScript Sourcebook - http://www.AppleScriptSourcebook.com
Vermont Recipes - http://www.stepwise.com/Articles/VermontRecipes


 _______________________________________________
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: Why add a nil item to an NSArray ? (From: Dave Hersey <email@hidden>)

  • Prev by Date: Re: Return in NSTableView--how detect a row change?
  • Next by Date: Replacing a method via categorys
  • 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