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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:32:36+00:00 2026-06-07T12:32:36+00:00

Any pointers for the right direction would be gratefully received, I have a NSDictionary

  • 0

Any pointers for the right direction would be gratefully received,

I have a NSDictionary of the format:

{
3 = "special-collection-procedures-see-notes|";
13 = "<p>None Given</p>";
16 = "";
6 = "<p>Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.</p>";
9 = "<p>Stored in laboratory at -20C</p>";
12 = "<p>None</p>";
2 = "images/tubes/lightblue_tube_large.png";
15 = "";
5 = "";
8 = "Up to 28 days";
11 = "<p>Some indications: Hereditary Angioedema</p><p>Sample type is citrated plasma though plain serum can also be used.</p>";
1 = " Functional C1 esterase inhibitor";
14 = "|";
4 = "5-10 mL";
7 = "<p>Frozen if unable to deliver within one hour</p>";
10 = "<p>expressed as a percentage of a control serum with 75% -125% being classed as normal.</p>";

}

Which I would like to sort the keys so that the order is:

1 = " Functional C1 esterase inhibitor";
2 = "images/tubes/lightblue_tube_large.png";

Etc.

I have this piece of code:

NSArray *myArray; 

myArray = [[valuesDictionary allKeys] sortedArrayUsingComparator: ^(id obj1, id obj2) {

    if ([obj1 integerValue] > [obj2 integerValue]) {

        return (NSComparisonResult)NSOrderedDescending;
    }
    if ([obj1 integerValue] < [obj2 integerValue]) {

        return (NSComparisonResult)NSOrderedAscending;
    }

    return (NSComparisonResult)NSOrderedSame;
}];

NSMutableDictionary *sortedDisplay = [[NSMutableDictionary alloc] init];

for (id object in myArray) {
    // do something with object
    [sortedDisplay setObject:[valuesDictionary objectForKey:object] forKey:object];

}

Which gives me a sorted myArray:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16

But the final “sorted” mutable dictionary is not sorted i.e its

Printing description of sortedDisplay:

{
13 = "<p>None Given</p>";
12 = "<p>None</p>";
11 = "<p>Some indications: Hereditary Angioedema</p><p>Sample type is citrated plasma though plain serum can also be used.</p>";
7 = "<p>Frozen if unable to deliver within one hour</p>";
6 = "<p>Arrange for sample to be separated at an interim site and subsequently transport frozen to lab, if it cannot reach lab within one hour.</p>";
2 = "images/tubes/lightblue_tube_large.png";
1 = " Functional C1 esterase inhibitor";
14 = "|";
15 = "";
10 = "<p>expressed as a percentage of a control serum with 75% -125% being classed as normal.</p>";
9 = "<p>Stored in laboratory at -20C</p>";
8 = "Up to 28 days";
5 = "";
4 = "5-10 mL";
3 = "special-collection-procedures-see-notes|";
16 = "";

}

What am I doing wrong?

  • 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-07T12:32:38+00:00Added an answer on June 7, 2026 at 12:32 pm

    Tommyo is right, you can’t sort a NSDictionary. Its purpose is to store and retrieve data efficiently in terms of performance.

    If you need to store data in a particular order, use an NSArray for the keys (as you are already doing), and use it to access the dictionary values when you need them.

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

Sidebar

Related Questions

Can anyone give me any pointers. I have a text file that contains dates
Does anyone have any pointers to good resources concerning mesh networks? Maybe I'm not
I'm new to postgreSQL, so would really appreciate any pointers from the community. I
Does anyone have any good samples, resources, pointers etc. for C# Silverlight with RIA
I'm looking for any pointers on how to write a rails web app without
Coming from a C# Background I never used any pointers. I'm creating a vector
When should I choose one over the other? Are there any pointers that you
I'm a DB2 newbie, so I'd appreciate even any pointers on where to start
I am using boost::any to store pointers and was wondering if there was a
Any reasons why this can not be standard behavior of free() ? multiple pointers

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.