You can't store nil
in a Foundation collection class such as NSArray
, you have to use NSNull
. To check to see if a member of the array is NSNull
, you would do this:
for (int i = 0; i < 6; i ++) {
if ([array objectAtIndex:i] == [NSNull null]) {
NSLog(@"object at index %i has no data", i);
}
}
If you want to see how many items are in the array, use -[NSArray count]
. If you want to iterate through the array to see if any object is NSNull
, but you don't care which one, you could use fast enumeration or -[NSArray containsObject:]
:
for (id anObject in array) {
if (anObject == [NSNull null]) {
// Do something
}
}
or
if ([array containsObject:[NSNull null]]) {
// Do something
}