• 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: Andrew White <email@hidden>
  • Date: Tue, 28 Jun 2005 12:51:44 +1000


Glen Simmons wrote:
On Jun 27, 2005, at 2:08 PM, Martin Ottenwaelter wrote:

Hi,

Why doesn't that works :
[NSArray initWithObjects:@"First",@"Second"];

Why do I have to add that nil item for the NSArray to be ok ?
[NSArray initWithObjects:@"First",@"Second",nil];


You're not adding nil to the array, you're letting the method know that your list is complete. Underneath, the method is iterating through the list until it finds nil. If it doesn't, it runs off the end and Bad Things happen.

And you can get really unpredictable results if the next item in memory just happens to be 'nil'. It will work at first, but then the value will be changed and you'll start getting all sorts of strange errors.


--
Andrew White

--------------------------------------------------------------------------
This email and any attachments may be confidential. They may contain legally
privileged information or copyright material. You should not read, copy,
use or disclose them without authorisation. If you are not an intended
recipient, please contact us at once by return email and then delete both
messages. We do not accept liability in connection with computer virus,
data corruption, delay, interruption, unauthorised access or unauthorised
amendment. This notice should not be removed.
_______________________________________________
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: Glen Simmons <email@hidden>)

  • Prev by Date: (resend) Problem subclassing NSXMLElement
  • 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: Return in NSTableView--how detect a row change?
  • Index(es):
    • Date
    • Thread