..
NSArray *allScores = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:12],
[NSNumber numberWithInt:43],
[NSNumber numberWithInt:5],nil];
int myScore = 44;
int myPosition = [self myPositionForScore:myScore inAllScores:allScores];
NSLog(@"myPosition: %i", myPosition);
..
- (int)myPositionForScore:(int)myScore inAllScores:(NSArray *)allScores
{
NSArray *sortedScores = [allScores sortedArrayUsingSelector:@selector(compare:)];
for (int position = 0; position < [sortedScores count]; position++) {
if (myScore <= [[sortedScores objectAtIndex:position] intValue]) {
return position + 1;
}
}
return [sortedScores count] +1;
}
solved How to get the index of the score from the stored array in game in ios using parse table. [closed]