I have a NSMutable Array and was trying to find the index number of the last object in this array. I tried this, but it feels cumbersome:
int currentCount = [[[self.myLibrary objectAtIndex:currentNoteBookNumber] tabColours] count];
NSLog(@"Number of tab colours total: %i", currentCount);
NSLog(@"Index number of last object: %i", currentCount-1);
Is there another way of doing this? The context of my problem is that I need to determine the last object in order to change it:
replaceObjectAtIndex:[last object] withObject: ...
Thanks!
If you need the index, then that is the way to do it (
int lastIndex = [array count] - 1;). If you just want to replace the last object with a different object however, you can do: