Question is short:
I have an array of some NSManagedObjects,
all of them have an NSDate attribute
Now I want to sort this arry by their date, the latest the first,
how could implement this?
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.
You want to use NSArray’s
sortedArrayUsingDescriptors:method with an NSSortDescriptor. If your array is calledarrayand the NSDate attribute is calleddate, then this would work:Also, note that when you’re getting these NSManagedObjects using an NSFetchRequest, you can give the request sortDescriptors so that they’re already sorted. Using the same
sortDescriptorsfrom above, just do the following before executing the request: