J'ai un tableau de tableaux. Les premiers éléments du tableau contenu sont tous des objets NSDate. Je voudrais trier le tableau contenant les tableaux dans l'ordre du plus récent au moins. Pour une raison quelconque, l'algorithme de tri ci-dessous entraîne une boucle infinie. Quelqu'un peut m'aider? Je vous remercie.Objectif C: Trier les tableaux bidimensionnels
meilleur ... SL
//array is the array containing all of the other arrays(that have NSDates as their first elements)
//temp is the new array being added to the end of the array, to later be sorted into the correct position.
[array addObject:temp];
NSMutableArray *tempArray;
for (int i=0; i<[array count]; i++)
{
NSDate *session1, *session2;
session1 = [[array objectAtIndex:i] objectAtIndex:0];
session2 = [[array objectAtIndex:[array count]-1] objectAtIndex:0];
if([session1 compare:session2] == NSOrderedDescending)
{
tempArray = [array objectAtIndex:i];
[array insertObject:[array objectAtIndex:[array count]-1] atIndex:i];
[array insertObject:tempArray atIndex:[array count]-1];
}
}
Merci beaucoup Kevin. Je n'étais pas au courant de telles capacités de tri intégrées. Cela m'aide énormément. – Skyler
@robmayoff: Euh, merci. Je ne sais pas comment je n'ai pas pensé à ça. –