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

  • SEARCH
  • Home
  • 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 8111169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:00:38+00:00 2026-06-06T02:00:38+00:00

I want to sort a NSMutableArray which has NSArrays with respect to the value

  • 0

I want to sort a NSMutableArray which has NSArrays with respect to the value at the index 1 of the NSArray. I’ll try to draw a picture of arrays.

NSMutableArray *ultimateHighscoreArray = { 
    ( (NSString) userName, (double) score, (int) numOfCorrectAnswers ) , 
      ( John , 4.5 , 3 ) , 
      ( Terry , 7.5 , 1) , 
                                     ... }

The first array within the NSMutableArray is an example which shows how examples are located. Second and third are how the values actually are. So, what I want is to sort these arrays having the array containing higher value at first index to go higher up in the ranking. For this example the array that has 7.5 which is Terry Array should go before the one that has 4.5 . I want the results to be held in a NSMutableArray in decreasing order. Thank you.

  • 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-06T02:00:39+00:00Added an answer on June 6, 2026 at 2:00 am

    This should do it:

    [ultimateHighscoreArray sortUsingComparator:^(id obj1, id obj2) {
        NSNumber *score1 = [obj1 objectAtIndex:1];
        NSNumber *score2 = [obj2 objectAtIndex:2];
    
        // Reverse the comparison here (compare score2 to score1)
        // in order to get a descending order
        return [score2 compare:score1];
    }];
    

    A general advice: your data structure would be clearer if it were an array of NSDictionary instances or even an array of custom objects (e.g., your custom Score class). In those cases, you could also use NSSortDescriptor to sort the array, which would result in cleaner, easier-to-read code.

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

Sidebar

Related Questions

I want to try sort by NSMutableDictionary 's value which key is price in
I want to sort a hash which actually has a hash as a value.
I have NSMutableArray* names , which contains NSStrings. I want to sort the array
i want to sort dictionary based upon value of each dictioanry item.but if i
I want to sort a String that has nr. How do I do that?
I want to sort alphabetically the NSMutableArray and add an object to the beginning
I want to sort an NSMutableArray alphabetically.
Possible Duplicate: Sort NSArray of date strings or objects Hello, I want to sort
I have a NSMutableArray with NSStrings and I want to sort them in alphabetical
For a little iPhone application I am making, I want to sort a NSMutableArray.

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.