Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:11:25+00:00 2026-06-09T22:11:25+00:00

I have used NSSortDescriptor to sort my objects using date as key. My code:

  • 0

I have used NSSortDescriptor to sort my objects using date as key. My code:

 NSLog(@"Before sorting: %@", temp);
    NSSortDescriptor *dateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey: @"date" ascending: YES];
    NSArray *sortedArray2 = [temp sortedArrayUsingDescriptors:[NSArray arrayWithObject: dateSortDescriptor]];
    NSLog(@"After sorting: %@", sortedArray2);
    NSMutableArray *afterSorting = [[(NSArray*)sortedArray2 mutableCopy]autorelease];

It worked well when the dates are

22/08/2012
23/08/2012
25/09/2012

However, I found that NSSortDescriptor only seemed to sort by the first two numbers in front because when my dates change a little, my result became like this:

10/09/2012
22/08/2012
23/08/2012

Can any one please advice? Saw many other posts using NSSortDescriptor as similar to my codes above but they seem to have no errors any where. For me, it only sort by the day but not the month! What I do is to sort objects with the nearer date on top. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:11:27+00:00Added an answer on June 9, 2026 at 10:11 pm

    The sort ordering you’ve shown is actually correct. The problem is that you’re sorting strings rather than dates. If possible, populate the date property with instances of NSDate rather than instances of NSString, and then the sort will do what you expect.

    If for some reason you can’t use NSDate instances in the date property (which would seem a little odd, but who knows), you can instead sort the array by sending it a sortedArrayUsingComparator: message, and passing in a block that defines your custom sort.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have used this code (kind of tutorial) at http://code.google.com/p/gwt-examples/wiki/gwt_hmtl5 ... In this code,
I have used following code to add three variables but instead of adding these
I have used ajax in the code which works perfectly and give me json
I have used an expander control to create some sort of slide-out panel which
I have used below code for displaying multiple marker in the google map and
Using Core Data, I have my fetchedResultsController with a with a date field. I
I have used FCKeditor in my project. It worked fine before i add url
I have used date picker in my iPad App but the output of date
I have successfully sorted the data I have by my sort key lastName ,
I have used traditional version control systems to maintain source code repositories on past

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.