Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Apr 4, 2009, 10:32 AM   #1
Soulstorm
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
How to insert nil to an NSArray?

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?
Soulstorm is offline   0 Reply With Quote
Old Apr 4, 2009, 10:47 AM   #2
dantherevelator
macrumors regular
 
Join Date: Oct 2007
Use an NSNull.
dantherevelator is offline   0 Reply With Quote
Old Apr 4, 2009, 11:21 AM   #3
lee1210
macrumors 68040
 
lee1210's Avatar
 
Join Date: Jan 2005
Location: 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.

-Lee
lee1210 is offline   0 Reply With Quote
Old Apr 5, 2009, 04:04 AM   #4
Soulstorm
Thread Starter
macrumors 68000
 
Soulstorm's Avatar
 
Join Date: Feb 2005
Quote:
Use an NSNull
From Apple docs:
Quote:
The NSNull instance is semantically equivalent to nil, however it is also important to appreciate that it is not equal to nil.
Quote:
Originally Posted by lee1210 View Post
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.

Last edited by Soulstorm; Apr 5, 2009 at 04:17 AM.
Soulstorm is offline   0 Reply With Quote
Old Apr 5, 2009, 06:25 AM   #5
eddietr
macrumors 6502a
 
Join Date: Oct 2006
Location: Virginia
Quote:
Originally Posted by Soulstorm View Post
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?
eddietr is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Nil value in variable when it should be non-nil moonman239 iPhone/iPad Programming 17 Apr 21, 2014 05:13 PM
UICollectionViewCell variable is nil moonman239 iPhone/iPad Programming 2 Feb 22, 2014 08:37 PM
Retrieved CGPath shows as nil.. RottenApple2 iPhone/iPad Programming 6 Sep 22, 2012 09:58 AM
Error Message: endSheet: requires a non-nil sheet rien333 Mac Programming 2 Sep 2, 2012 01:46 PM
Why would I get nil for [self.tableView cellForRowAtIndexPath:indexPath]? Ron C iPhone/iPad Programming 20 Jun 8, 2012 06:56 PM

Forum Jump

All times are GMT -5. The time now is 07:25 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC