Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios how to check if object in array in particular index exist? [closed]

I have nsmutable array and I want to add object at particular index, how can I check if the array at particular index has a object or not?

I was doing this:

if ([self.myArray objectAtIndex:index] !=nil) {

but I'm getting exceptions most of the time because "beyond bounds"

I'll really appreciate your help

like image 345
Juan Avatar asked Oct 02 '12 19:10

Juan


1 Answers

Easiest (may be not the best) will be

if ([self.myArray count] > index && [self.myArray objectAtIndex:index] !=nil)
like image 54
OgreSwamp Avatar answered Oct 04 '22 00:10

OgreSwamp