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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:00:53+00:00 2026-05-17T00:00:53+00:00

I have an NSDictionary. It has keys and objects. For the purposes of simplicity

  • 0

I have an NSDictionary. It has keys and objects.

For the purposes of simplicity the keys are Question numbers and the objects are calculated Answer scores.

Now how I did it before was that I set the answer score as the keys and the question numbers as the objects. This way I could get an array of allKeys from the dictionary, sort it and then do something similar to:

for(NSString *string in tempArray){
  NSLog(@"%@",[dictionary objectForKey:string]);
}

The (stupid – on my part) problem that I have now encountered however is that (obviously… duuhhh) the keys need to unique, and therefore when the calculated answer scores are the same, only one answer gets output!

I need a solution to this. In PHP you can multisort arrays. I was wondering if there was some similar solution in objective-c or indeed if someone had a better answer?

Any help here would be much appreciated.

Thank you.

  • 1 1 Answer
  • 3 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-05-17T00:00:54+00:00Added an answer on May 17, 2026 at 12:00 am

    One solution is to store the answer scores using an array of dictionaries containing only two key-value pairs. One key is the question number (or however your questions are tagged, i.e. “Q1.1”), while the other key is the actual answer score. For example:

    static NSString * const QuestionKey = @"questionNumber";
    static NSString * const AnswerScoreKey = @"answerScore";
    
    NSMutableArray *allAnswers = [NSMutableArray array];
    
    for (int i = 0; i < 20; i++)
    {
        // fill allAnswers array with random data
        NSDictionary *answer = [NSDictionary dictionaryWithObjectsForKeys:
            [NSString stringWithFormat:@"Q%d", i], QuestionKey,
            [NSNumber numberWithInt:rand()], AnswerScoreKey,
             nil];
    
        [allAnswers addObject:answer];
    }
    
    // sort the allAnswers array based on score, highest first
    NSSortDescriptor *sortDesc = [NSSortDescriptor sortDescriptorWithKey:AnswerScoreKey ascending:NO];
    
    [allAnswers sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
    
    for (NSDictionary *answer in allAnswers)
    {
        NSLog(@"Question: %@, AnswerScore: %@", [answer objectForKey:QuestionKey], [answer objectForKey:AnswerScoreKey];
    }
    

    Disclaimer:

    Untested and uncompiled code. Theory only.

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

Sidebar

Related Questions

I have an NSArray full of NSDictionary objects, and each NSDictionary has a unique
I have an NSDictionary which contains (my custom) GTPerson objects. GTPerson has an NSMutableSet
I have some NSDictionary objects stored in an NSArray called telephoneArray . I fetch
the question explains it all. For instance, if I have a NSDictionary like this
I have a large list of Users in an NSDictionary that has a structure
I have an object at the root of plist that stores objects and keys
I have a array (dataArray) of NSDictionary item. It has datas like david for
I have NSDictionaries stored in an NSMutableArray. Each NSDictionary has a NSNumber inside of
I have a simple NSArray which has some arrays as objects which has some
I have an existing NSDictionary that has: { charts_count = 2; created_at = 2010-04-12T16:37:32Z;

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.