Re: Why add a nil item to an NSArray ?
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