Objective-C : Sorting NSMutableArray containing NSMutableArrays

Posted by Dough on Stack Overflow See other posts from Stack Overflow or by Dough
Published on 2010-05-04T16:13:42Z Indexed on 2010/05/04 16:18 UTC
Read the original article Hit count: 671

Hi !

I'm currently using NSMutableArrays in my developments to store some data taken from an HTTP Servlet.

Everything is fine since now I have to sort what is in my array.

This is what I do :

NSMutableArray *array = [[NSMutableArray arrayWithObjects:nil] retain];
[array addObject:[NSArray arrayWithObjects: "Label 1", 1, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 2", 4, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 3", 2, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 4", 6, nil]];
[array addObject:[NSArray arrayWithObjects: "Label 5", 0, nil]];

First column contain a Label and 2nd one is a score I want the array to be sorted descending.

Is the way I am storing my data a good one ? Is there a better way to do this than using NSMutableArrays in NSMutableArray ?

I'm new to iPhone dev, I've seen some code about sorting but didn't feel good with that.

Thanks in advance for your answers !

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about nsmutablearray