0
NSMutableArray *OneNameArray  = [NSMutableArray arrayWithArray:ScoreNameArray];
NSMutableArray *OneScoreArray = [NSMutableArray arrayWithArray:RoundOneScoreArray];


NSDictionary *temp = [NSDictionary dictionaryWithObjects:OneNameArray forKeys:OneScoreArray];
NSSortDescriptor *theDescriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:NO selector:@selector(localizedStandardCompare:)];    
RoundOneScoreArray = [[temp allKeys] sortedArrayUsingDescriptors:[NSArray arrayWithObject:theDescriptor]];
ScoreNameArray = [temp objectsForKeys:RoundOneScoreArray notFoundMarker:[NSNull null]];

If theres 2 numbers in common in the score array, then it'll delete one of the numbers.. How can i fix that?

Thanks <3

Lollo
  • 112
  • 5
  • Try this link.. http://stackoverflow.com/questions/1025674/the-best-way-to-remove-duplicate-values-from-nsmutablearray-in-objective-c – Hardeep Singh Aug 27 '12 at 17:05
  • Just to clarify: are you trying to keep the duplicates if they occur, or do you want the duplicates to be eliminated? – Husker Jeff Aug 27 '12 at 17:12
  • 2
    NSDictionary can't have duplicate keys which is why this is happening I think. Also, friendly reminder, if you want people to read and understand your Objective-C code you should conform to certain style guidelines one of which is don't have variables with capitalized names. – Carl Veazey Aug 27 '12 at 17:12

2 Answers2

0

What I suggest you do is instead of using mutable arrays, use a mutable dictionary. Use a NSNumber as the key, and the name as the object. When you add a new key-value pair, where the key is the same as an older one, the older one will be lost and the newer one kept.

This should greatly reduce your code complexity.

David H
  • 40,852
  • 12
  • 92
  • 138
0

My understanding is that you have an array of names and array of scores. The names are associated to the score by the index of the array (i.e. name[i] has score[i]). In this case one solution will be to implement a sorting algorithm that sorts the array of scores, and takes the array of names along for the ride.

Or perhaps a better plan may be to have the name object have an NSArray member variable that contains that players score for each round. Then you can sort the name array by the score for a given round. Is there any reason this wouldn't work?

Sean Lynch
  • 223
  • 1
  • 4