Hi all,
I have been going over this for hours and cannot find the problem. I have an array of scores which I save at the end of a game in a core data model. After saving when I go back into the high scores viewcontroller I load the scores from core data and sort the array using the following function where scores array is an NSMutableArray with my 10 high scores
[self.scoresArray sortUsingFunction:firstNumSort context:@selector(totalScore)];
//function to sort high scores in the array
NSInteger firstNumSort(id str1, id str2, void *context) {
static int counter = 0;
NSLog(@"counter = %d", counter);
counter++;
//NSLog(@"should be sorting");
int num1 = [str1 totalScore];
int num2 = [str2 totalScore];
if (num1 > num2) {
NSLog(@"%@ is greater than %@", num1, num2);
return NSOrderedAscending;
}
else if (num1 < num2){
NSLog(@"%@ is less than %@", num1, num2);
return NSOrderedDescending;
}
else {
NSLog(@"%@ is the same as %@", num1, num2);
return NSOrderedSame;
}
}
This always places the last score entry at the top of the list regardless of its value?? The stranger thing is that when I restart my app the same function puts all scores in correct descending order which is what I want, but obviously I dont want the user to have to restart the app to see the scores displayed in the correct order. Can anyone please shed some light on what is going on??
Many thanks
Jules