How to insert nil to an NSArray?

Discussion in 'Mac Programming' started by Soulstorm, Apr 4, 2009.

  1. Soulstorm macrumors 68000


    Feb 1, 2005
    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?
  2. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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.

  3. Soulstorm thread starter macrumors 68000


    Feb 1, 2005
    From Apple docs:
    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.
  4. eddietr macrumors 6502a

    Oct 29, 2006
    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?

Share This Page