Possible Duplicate:
How to sort an NSMutableArray with custom objects in it?
How does one sort an array of objects by accessing their NSDate properties?
I know one can use [mutableArray sortUsingSelector:@selector(compare:)];
on an array of dates, but how does one do it by accessing a NSDate property on each element in the array, sorting the objects by earliest date to latest date?
You can use:
Or see this link
You can override the compare method in your custom class so that it compares two objects of your custom class and returns the appropriate NSComparisonResult according to the dates on the objects.
Eg:
There is a method called
-[NSArray sortedArrayUsingComparator:]
. It takes a block in which you can implement any comparison you see fit for your objects.Thanks for all the answers, I came across this answer that solved my problem.Check NSGod's answer
Here is the code thanks to user: NSGod: