views:

319

answers:

2

I have to sort objects based on NSDates. What are the options for sorting by NSDate?

+1  A: 

In general you use a NSSortDescriptor to define the sort of collections like arrays or Core Data. You call the sort from the collection object itself.

NSDate itself has comparison functions if you want to do the sort directly yourself.

TechZen
+1  A: 

You can do sorting of date by comparing two dates.For that you should use. NSComparisonResult class. NSComparisonResult result=[date1 compare:date2];

if result==NSorderSame then date1 and date2 is Same.

result==NSOrderedAscending then date1 is smaller than date2.

result==NSOrderedDescending then date1 is greater than date2.

Apoorv