• 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: Glen Simmons <email@hidden>
  • Date: Mon, 27 Jun 2005 14:37:54 -0500

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.


Glen
_______________________________________________
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: Why add a nil item to an NSArray ?
      • From: Andrew White <email@hidden>
References: 
 >Why add a nil item to an NSArray ? (From: Martin Ottenwaelter <email@hidden>)

  • Prev by Date: Re: Why add a nil item to an NSArray ?
  • Next by Date: Re: Multiple singletons
  • 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