baste baste - 1 year ago 132
Objective-C Question

How to sort an array of dates in descending order

I have a NSDictionary that parsed to an array one of the element is date, i tried using

[startimeArray sortUsingSelector:@selector(compare:)];
(starttimeArray) is my date but it only arrange ascending. how can i sort in descending order. thanks

Answer Source

Sort the array by puting NO is ascending parameter:

NSSortDescriptor *descriptor=[[NSSortDescriptor alloc] initWithKey:@"self" ascending:NO];
NSArray *descriptors=[NSArray arrayWithObject: descriptor];
NSArray *reverseOrder=[dateArray sortedArrayUsingDescriptors:descriptors];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download