Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object at index in NSArray

Tags:

arrays

ios

iphone

I have an array. I want to check whether there is an object present in a particular index or not. How to do this? Please help.

like image 319
hgpl Avatar asked Jun 27 '12 11:06

hgpl


2 Answers

if you just want to check if there is an object

if (myIndex < [array count])

if you want to find a specific object

[array indexOfObject:myObject];

if you want to know if the object at some index is of some class

[[array objectAtIndex:myIndex] isKindOfClass:[TheClassToCompareTo class]];
like image 71
Pfitz Avatar answered Sep 19 '22 16:09

Pfitz


BOOL exists = index < [array count] ? YES : NO;

like image 22
onegray Avatar answered Sep 19 '22 16:09

onegray