Friday, June 3, 2011

Creating an Empty Array

To create an empty array use NSNull:

NSNull *myNull = [NSNull null];
NSMutableArray *arr = [NSMutableArray arrayWithObjects: myNull, myNull, nil];


Then to compare use something like:

if ([arr objectAtIndex:index]  == (id)[NSNull null]) {

  //do something
}


nil cannot be added into an Array or collection similar to how an int cannot be added.  NSNull is the helper object to get nil into the collection.  In Objective C there's nil, NSNull and Null.

No comments:

Post a Comment