views:

17

answers:

1

Hello,

I have an NSMutableArray which holds the dates in format dd/MM/yyyy of type NSString. Now i need to display the sorted array of dates. Please suggest me how to achieve it.

Thank You.

+2  A: 

I can think of two options:

  1. You can use NSMutableArray's sortUsingFunction or sortUsingSelector etc. methods. Create the sort method or function which takes string parameters (array object's datatype), converts the strings to dates using NSDateFormatter's dateFromString method, compares the two dates using NSDate's compare method and return the comparison result. For a typical example of the sort function for an array, see NSArray class reference - sortedArrayUsingFunction.

  2. Implement any of typical sort algorithms (like quick sort) yourself. In the implementation convert the date to string before you compare two elements.

lukya