PDA

View Full Version : How to insert nil to an NSArray?




Soulstorm
Apr 4, 2009, 10:32 AM
In my program I have a problem.

I want to be able to make an NSMutable array that accepts as many arguments as I want, and I want to be able to insert a 'nil' at its end.

Is that possible?



dantherevelator
Apr 4, 2009, 10:47 AM
Use an NSNull.

lee1210
Apr 4, 2009, 11:21 AM
why do you want to do this? You can ask an array for it's length, so you don't need a special element to tell you you're at the end.

-Lee

Soulstorm
Apr 5, 2009, 04:04 AM
Use an NSNull
From Apple docs:
The NSNull instance is semantically equivalent to nil, however it is also important to appreciate that it is not equal to nil.

why do you want to do this? You can ask an array for it's length, so you don't need a special element to tell you you're at the end.

-Lee

I am building an extension to an existing library for which I don't have the original source. Inside that library, there is a class that has a function that accepts variable arguments, with nil at the end.

eddietr
Apr 5, 2009, 06:25 AM
I am building an extension to an existing library for which I don't have the original source. Inside that library, there is a class that has a function that accepts variable arguments, with nil at the end.

Well, that function doesn't accept an NSArray then, right?

So I would add the terminating nil when you actually call that function (in other words, when you construct the list for that function). Maybe add a category to NSArray with a method that returns this arg list null terminated for you.

Unless I'm not understanding what you are trying to do?