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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:27:12+00:00 2026-05-27T05:27:12+00:00

I have some questione about NSMutableDictionary. I read that they are only a wrapper

  • 0

I have some questione about NSMutableDictionary. I read that they are only a wrapper around an hashmap, so their use for ordered list is discouraged.

But I have to use it, so the problems began…

I save the result of a Json (after a call to an URL) in a NSMutableDictionary and then I have two different “print”:

  • if I try to print the dictionary from console with command “po myDictionary” I have an order (the order of the original json)
  • if I create a simple “for statement” and print every elements in myDictionary, I have a different order.

How is it possible? Shouldn’t they have the same order?

Thank to all!

EDIT: this is a little example of the code:

NSMutableDictionary *myDictionary = [--{RECEIVED FROM ANOTHER CALL}--];
NSMutableDictionary *tmp = [NSMutableDictionary dictionaryWithCapacity:[myDictionary count]];

for(NSString *key in myDictionary) {
    NSLog(@"%@", key);

    NSObject *object = [[NSObject alloc] init]

    /* some operation in the code with object */

    [tmp setObject:object forKey:key];
}

After the “for statement” this is what happened:

  • if I see all the logs I receive something (for example if myDictionary has the name of the day I have something like “Saturday, Monday, Friday…..”)
  • if I insert a breakpoint here and try to print something from console with the command “po myDictionary” I have another order, (“sunday, tuesday, monday, …”)

The question is: why?

EDIT 2: I know that there exists a system to have an “OrderedDictionary”, but it isn’t the question: I want to understand why I have two different print, one from the “for statement” and the other from “po command”.

  • 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-05-27T05:27:13+00:00Added an answer on May 27, 2026 at 5:27 am

    The po <object> command in gdb prints the output of [<object> description]. [NSDictionary description] sorts its output by key. This is documented behavior.

    If your JSON is sorted by key (which it sounds like it is), then you can just sort by key again to ensure a reliable order.

    Note that if your JSON is using an object (a collection of key/value pairs) to represent ordered data, it is in violation of the JSON spec.

    An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.

    The correct encoding is an array of single-key objects such as:

    [ { "firstKey": "value" }, { "secondKey": "value" } ]
    

    But if you can use sorted keys to define order, that’s appropriate.

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

Sidebar

Related Questions

I have some question about WH_MOUSE. From what I've read, by putting the hook
i have some questions about constructors in ColdFusion : must i use the name
I have some questions about glPrimitiveRestartIndex and how to use it. Basically, I want
I have some questions about protocols in OBJ-C. I often see lines that declare
I have some questions about partitioning and strategy, how and when to use it.
I have some questions about android ui api. Give a example, that I want
I have some questions about some things in Asp.net MVC that still confuses me.
I have some questions about the search functions in artificial intelligence that I cannot
I have some questions about pthreads in linux: Is it the case that pthread_t
I have some question about the privacy issues using Google Analytics. I've heard that

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.