Sorting Array Using NSSortDescriptor

Ab'initio picture Ab'initio · Mar 21, 2013 · Viewed 19.2k times · Source

I have an array of class A objects, let it be detailsArray.

Class A has date, name as properties.

Can any one suggest a good method to sort this array based on date?

How can I use NSSortDescriptor to sort this array? I know sorting array of dictionary using NSSortDescriptor...

Any help is greatly appreciated.....

Answer

Nick C picture Nick C · Mar 21, 2013
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"date" ascending:NO];
NSArray *sortedArray = [detailsArray sortedArrayUsingDescriptors:@[sortDescriptor]];