we are trying to add objects to an array , and when its full( capacity=10) , to shift all the values forward and erase the first (such as shift register)
i was trying to do the next and it allways crash after 10, because 9 beyond bounds of 8..??
if (count>9)
{
for(count=0;count<9;count++)
{
NSLog(@"%@",listOfEvents);
[listOfEvents removeObjectAtIndex:count];
[listOfEvents insertObject:[listOfEvents objectAtIndex:(count+1)] atIndex:count];
}
[listOfEvents removeObjectAtIndex:9];
[listOfEvents insertObject:event atIndex: 9];
}
else
[listOfEvents addObject:event];
count++;
when i have tried without removing object ,i get another error .
what am i doing wrong?
why cant i add values to some index, when there is a space index befor him? ?
thanks a lot .
You don’t actually have to do it this way, since
NSArraywill perform the “downsliding” of elements on its own:(NSMutableArray)
So
should be sufficient.
NSMutableArraybehaves more like anArrayListin Java, or aListin C#, and less like a plain C array.