How to insert nil to an NSArray?

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

  1. macrumors 68000

    Soulstorm

    #1
    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. macrumors regular

    #2
    Use an NSNull.
     
  3. macrumors 68040

    lee1210

    #3
    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
     
  4. macrumors 68000

    Soulstorm

    #4
    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.
     
  5. macrumors 6502a

    #5
    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