How to insert nil to an NSArray?

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

  1. macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #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

    Joined:
    Oct 8, 2007
    #2
    Use an NSNull.
     
  3. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #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. thread starter macrumors 68000

    Soulstorm

    Joined:
    Feb 1, 2005
    #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

    Joined:
    Oct 29, 2006
    Location:
    Virginia
    #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