I cant find this any where, I may be searching the wrong terms or words but I just need to know how to check if an array is a certain length:
if ([scores objectAtIndex:3]){
//code
}
This comes up with an error and crashes if the array isnt this long yet, but surly this should just check if there is an index, and if not move on??
How to I check this without the app crashing??
countmethod of NSArray returns the number of objects in the array. If[myArray count]returnsnthen valid indexes are0ton - 1. There is no automatic move on if the index is not valid. Before trying to access an index you need to make sure that the index is valid.if ([scores count] >= 4) { id obj = [scores objectAtIndex:3]; }