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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:31:42+00:00 2026-06-14T09:31:42+00:00

I executed the following code NSLog(@%@, arrData); and the output in the debugger was

  • 0

I executed the following code NSLog(@"%@", arrData); and the output in the debugger was expected like so:

    "0." =     {
"first_name"="John"
    };

    "1." =     {
"first_name"="Florence"
    };

    "2." =     {
"first_name"="Melinda"
    };
    "3." =     {
"first_name"="Zack"
    };

I then executed this code:

for (NSDictionary *book in arrData)
{
        NSLog(@"%@ %@" , book, [[arrData objectForKey:book]  objectForKey:@"first_name"]);
}

And the output was like so:

2. Melinda
0. John
3. Zack
1. Florence

How do I make the for loop print the results in the same order as ? NSLog(@"%@", arrData);

  • 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-14T09:31:43+00:00Added an answer on June 14, 2026 at 9:31 am

    A few things are going on here.

    First let’s understand what %@ means in NSLog. Many iOS/Cocoa developers incorrectly believe %@ is associated with NSString, it’s not. From Apple’s documentation:

    Objective-C object, printed as the string returned by descriptionWithLocale:if available, or description otherwise. Also works with CFTypeRef objects, returning the result of the CFCopyDescription function.

    So, %@ takes any Objective-C or CFTypeRef object. Since you are using a NSDictionary, %@ will print the output of description or descriptionWithLocale:(id)locale. So what does that do? Again, from Apple’s documentation:

    If each key in the dictionary is an NSString object, the entries are listed in ascending order by key, otherwise the order in which the entries are listed is undefined.

    When using the for-in loop, aka Fast-Enumeration, the order of the objects is undefined, so that is why the output of the loop is not in order. If you wanted to print the contents of an NSDictionary in order, you’ll have to emulate the behavior of the description method.

    From this stackoverflow post:

    NSArray *sortedKeys = [[dict allKeys] sortedArrayUsingSelector: @selector(compare:)];
    NSMutableArray *sortedValues = [NSMutableArray array];
    for (NSString *key in sortedKeys) {
        [sortedValues addObject: [dict objectForKey: key]];
    }
    

    I hope this clears things up.

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

Sidebar

Related Questions

Assuming A.sql contains the following code, then second Select query won’t be executed due
i executed the following c code on my ubuntu machine...i have read about fcntl()'s
Following code gets executed whenever I want to persist any entity. Things seems to
The following code doesn't appear to run when executed by code: Stored procedure snippet:
Suppose the following code is executed on the 22nd of August 2009 (a Saturday)
I have the following code which is executed from the command line: import cgi,time,os,json,sys,zipfile,urllib2
I ran the following code, and it stated is executed correctly. It is the
I have the following code - (void) viewWillAppear:(BOOL)animated { NSLog(@dismiss view); [self dismissModalViewControllerAnimated:YES]; }
I wrote a unit test for my code. The code looks like the following:
The following code works fine when executed directly in Sql server: DECLARE @cmd sysname

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.