I can’t figure out how to sort my array. It’s an array with dictionaries with dictionaries inside. So to get the startdate I would need to write
NSDictionary *object = [array objectAtIndex:0];
[[array objectForKey:@"DATE"]objectForKey:@"startDate"];
I want to sort the array, but because I need to sort it accordingly to the second dictionary I cant use this:
[array sortUsingDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"startDate" ascending:YES]]];
I guess I just need to make some small adjustment, but I can’t figure out how.
First of all the line that you get your objects should be called on
objectinstead ofarray. Furthermore you could usevalueForKeyPathinstead ofobjectForKeyfor nested dictionaries. Something like this:Now you just apply the same thing to your sort descriptor:
Keep in mind though that
sortUsingDescriptors:ascending:it’s a method that sorts in place and must be called on anNSMutableArray. If you just want a sorted copy of your array then usesortedArrayUsingDescriptors:method instead. I hope that this makes sense…