I’ve got NSMutableArray with objects Link which has parameter Byte taskOne. I have to sort objects by this parameter.
for (Byte i = 0; i < [linksArray count]-1; i++) {
Link *l = [linksArray objectAtIndex:i];
Link *lNext = [linksArray objectAtIndex:i+1];
if (l.taskOne >= lNext.taskOne) {
NSLog(@"%d >= %d", l.taskOne, lNext.taskOne);
[linksArray replaceObjectAtIndex:i withObject:lNext];
[linksArray replaceObjectAtIndex:i+1 withObject:l];
}
}
this give me wrong results, but i don’t know what’s wrong.
thank you for help.
The easiest way to sort an array is to use
NSSortDescriptorwith KVC, like this:This will create a new array. To sort an
NSMutableArrayin place, do this: