Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sorting Array of custom class object by date property

I have an array of objects created from a custom class. Each object has an NSDate property. What is the easiest and quickest way to order all of these objects based on their dates properties? (in order from most recent to least recent).

like image 657
byteSlayer Avatar asked Nov 28 '22 17:11

byteSlayer


1 Answers

NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"thisIsTheNameOfYourDateProperty" ascending:NO];
NSArray *orderedArray = [arrayOfCustomObjects sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
like image 154
Darren Avatar answered Dec 10 '22 10:12

Darren