Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort JSON NSDictionary for UITableView

I am using TouchJSON to retrieve info for my app and put it in a dictionary. I would like to be able to sort it by values like difficulty and rating. How would I go about this? I have included my .m file. Thanks, enbr http://pastie.org/1091334

like image 847
enbr Avatar asked Aug 03 '26 18:08

enbr


1 Answers

You can probably use NSSortDescriptor to sort the array of dictionaries with specified keys. So, for example, the following can sort the array by the key "ratings" in each dictionary:

NSSortDescriptor *ratingsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"ratings" ascending:YES] autorelease];
rows = [rows sortedArrayUsingDescriptors:[NSArray arrayWithObject:ratingsSortDescriptor]];
like image 88
William Niu Avatar answered Aug 05 '26 08:08

William Niu