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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I can think of two options:
You can use NSMutableArray’s
sortUsingFunctionorsortUsingSelectoretc. methods. Create the sort method or function which takes string parameters (array object’s datatype), converts the strings to dates using NSDateFormatter’sdateFromStringmethod, compares the two dates using NSDate’scomparemethod and return the comparison result. For a typical example of the sort function for an array, see NSArray class reference – sortedArrayUsingFunction.Implement any of typical sort algorithms (like quick sort) yourself. In the implementation convert the date to string before you compare two elements.