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 7898639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:29:14+00:00 2026-06-03T08:29:14+00:00

note from N00B land again. I have read lots about sorting arrays – wanted

  • 0

note from N00B land again. I have read lots about sorting arrays – wanted to try the block method, but haven’t wrapped my head around it. Instead, I opted for the descriptors method. I read this Sort NSArray of custom objects by their NSDate properties and this How to sort an NSMutableArray with custom objects in it? amongst oodles and oodles of others. In my code I did this:

NSString *lastHighScore = @"_highScore";
NSString *dateScoreCreated = @"_dateCreated";
NSSortDescriptor *highScoreDescriptor = [[[NSSortDescriptor alloc]
    initWithKey:lastHighScore                                        
    ascending:NO                                          
    selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];

NSSortDescriptor *dateScoreCreatedDescriptor = [[[NSSortDescriptor alloc]
                                      initWithKey:dateScoreCreated
                                      ascending:NO
    selector:@selector(localizedCaseInsensitiveCompare:)] autorelease];
NSArray *descriptors = [NSArray arrayWithObjects:highScoreDescriptor, 
dateScoreCreatedDescriptor, nil];

NSArray *sortedArray = [[[FlipHighScoreStore sharedStore] allHighScores] sortedArrayUsingDescriptors:descriptors];

Sadly, I am getting an error to begin with – initializer element is not a compile-time element. I looked this up and tried setting NSSortDescriptor *highScoreDescriptor = nil but then I get a warning saying that highScoreDescriptor “Type Specifier Missing, default to int” which in this case is ok, but is not so ok for the Date object in the next descriptor. (Turns out I am also getting an error saying that I am redefining highSoreDescriptor with a different type.)

Also, is there a list somewhere of what selectors are available? I doubt that localizedCaseInsensitiveCompare: is what I want to use since the first property “_highScore” is an int and the second “_dateCreated” is a date. I read somewhere that the default is “compare” so can I just put “compare:”? (Found one answer, I think – I can use (intValue) for the first descriptor:

selector:@selector(intValue)] autorelease];

More reading makes me think that I can do away with the selector line entirely for the date sort. Is that correct?

Lastly, if I say ascending:NO is that the same as descending? I would guess that it is, but one never knows with programming, does one?

Do I wrap all of this code in its own method? Or can I (until later) just plunk it in the code where I am laying out the table?

This project is not ARC.

  • 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-03T08:29:16+00:00Added an answer on June 3, 2026 at 8:29 am

    To answer my own question, with a little help from a friend, I was basically doing two things wrong. First, I was writing the code outside of a method – which is why I was getting all of the errors about initializer elements. I guess I was very tired when I was adding this.

    As for the actual sorting, I deleted the selector option from the descriptor description and the sorting actually happened!

    Lastly, yes, ascending:NO is equal to descending.

    The last bit, will have to wait until I a ready to tackle more refactoring of the application.

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

Sidebar

Related Questions

Note: This question has broadened in scope from previous revisions. I have tried to
Note The question below was asked in 2008 about some code from 2003. As
This is the query I'm talking about: SELECT COUNT FROM Note N, DatePCC D
Note: This code actually codes from a tutorial book I'm reading at the moment,
Note: I am cross-posting this from App Engine group because I got no answers
[Please note that this is a different question from the already answered How to
Note: I'm relatively new to Objective-C and am coming from Java and PHP. Could
Please note that this question is from 2008 and now is of only historic
Quoting from the cakephp Book (ver 1.3): Note that only fields of the model
From http://www.jibbering.com/faq/faq_notes/closures.html : Note: ECMAScript defines an internal [[prototype]] property of the internal Object

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.