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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:37:54+00:00 2026-05-13T08:37:54+00:00

So I have an NSDictionary where the keys are years as NSString ‘s and

  • 0

So I have an NSDictionary where the keys are years as NSString‘s and the value for each key is also an NSString which is sort of a description for the year. So for example, one key is “943 B.C.”, another “1886”. The problem I am encountering is that I want to sort them, naturally, in ascending order.

The thing is that the data source of these years is already in order, it’s just that when I go ahead and call setValue:forKey the order is lost, naturally. I imagine figuring out a way to sort these NSString‘s might be a pain and instead I should look for a method of preserving the order at the insertion phase. What should I do? Should I instead make this an NSMutableArray in which every object is actually an NSDictionary consisting of the key being the year and the value being the description?

I guess I just answered my own question, but to avoid having wasted this time I’ll leave this up in case anyone can recommend a better way of doing this.

Thanks!

EDIT: I went ahead with my own idea of NSMutableArray with NSDictionary entries to hold the key/value pairs. This is how I am accessing the information later on, hopefully I’m doing this correctly:

// parsedData is the NSMutableArray which holdes the NSDictionary entries   
for (id entry in parsedData) {
    NSString *year = [[entry allKeys] objectAtIndex:0];
    NSString *text = [entry objectForKey:year];

    NSLog(@"Year: %@, Text: %@", year, text);
}
  • 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-13T08:37:54+00:00Added an answer on May 13, 2026 at 8:37 am

    You could either do it as an array of dictionaries, as you suggest, or as an array of strings where the strings are the keys to your original dictionary. The latter is probably a simpler way of going about it. NSDictionary does not, as I understand it, maintain any particular ordering of its keys, so attempting to sort the values there may be unwise.

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

Sidebar

Related Questions

I have an NSArray which contains NSDictionary objects with keys that are NSNumber objects.
Is it possible to have an NSdictionary where the keys are NSDates and also
I have an NSArray of NSDictionaries each of which has 4 key values. I'm
Just for example I have next NSDictionary { { first_name = Paul; last_name =
I have an NSArray of NSDictionary objects which I would like to be able
I have a plist which contains an array of NSDictionary 's which represent a
I have an NSDictionary with 5 keys and corresponding values. How can I set
I have an NSDictionary where both the keys and values are NSStrings and I'd
I have an NSDictionary with NSStrings Some of the valueForKey:@Key have no entry so
I have a dictionary of keys and values, for example: { fred: 1, dave:

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.