Hi,
I'm struggling with trying to sort an array of dictionarys.
My dictionaries have a couple of values of interest, price, popularity etc.
Any suggestions?
Hi,
I'm struggling with trying to sort an array of dictionarys.
My dictionaries have a couple of values of interest, price, popularity etc.
Any suggestions?
Write a sort function that compares the relevant fields in two dictionaries. When you have this version you can for example use NSArray#sortedArrayUsingFunction:context:
to sort your array.
Use NSSortDescriptor like this..
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES];
[stories sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
recent = [stories copy];
Stories is the array you want to sort .recent is another mutable array which has sorted dictionary values.change the "interest" with the key value on which you have to sort.
All the best