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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:53:20+00:00 2026-06-01T15:53:20+00:00

I am new to Objective-C and iPhone I have to sort a NSDictionary using

  • 0

I am new to Objective-C and iPhone

I have to sort a NSDictionary using values and according to that i have to arrange the keys of that values, i have sorted the array.

//getting values
NSArray* keys1 = [sortDictionary allValues];    
NSArray* sortedArray = [keys1 sortedArrayUsingComparator:^(id a, id b) {  
     return [a compare:b options:NSNumericSearch];
}]; 

My problem now is I am getting the keys of the values by allKeysForObject: , which returns an NSArray.

for( NSString* aStr in sortedArray ) {
    NSLog( @"%@ has value %@", [sortDictionary allKeysForObject:aStr], aStr );  
 }    
O/P :- (
  Sourish
) has value 60

Rather i want “Sourish” as a string and store it to a NSArray and than store that NSArray to NSDictionary or store both Sourish and 60 to another NSDictionary

Kindly make me to sort our this problem.

  • 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-01T15:53:21+00:00Added an answer on June 1, 2026 at 3:53 pm

    This gets the string for you by looking at the array. Is that what you are after?

    NSDictionary* sortDictionary = [NSDictionary dictionaryWithObjectsAndKeys: @"60", @"Sourish", @"45" , @"Peckish",  @"25", @"Swordfish", @"15", @"Mashmish", nil];
    
     NSArray* keys1 = [sortDictionary allValues];    
     NSArray* sortedArray = [keys1 sortedArrayUsingComparator:^(id a, id b)
     {  
        return [a compare:b options:NSNumericSearch];
     }]; 
    
     for( NSString* aStr in sortedArray )
     {
        NSString* keyForObject = @"";
    
        if ([[sortDictionary allKeysForObject: aStr] count] > 0)
        {
            keyForObject = [[sortDictionary allKeysForObject: aStr] objectAtIndex: 0];
        }
    
         NSLog( @"%@ has value %@", keyForObject, aStr );  
     }  
    

    This logs:

    Mashmish has value 15
    Swordfish has value 25
    Peckish has value 45
    Sourish has value 60
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Objective-C and iPhone development and have been using Apress' Beginning iPhone
I'm relatively new to objective-c...I'm using the iphone 3.0 SDK I have a UIView,
I am new to the whole iPhone SDK and objective C, but have managed
I'm new to Objective-C and iPhone development, and I'm trying to store floating-point values
I am new to Objective C and iPhone development. I am using CoreData on
First off I am very new to Objective C and iPhone programming. Now that
im new with objective-c. I have problem with memory leaking when developing iphone app.
I am new in iPhone development and Objective-C. I have RootViewController and DetailViewController. I
I am new to objective-c and started iphone application development. I have noticed the
I'm new to Objective-C and the iPhone and thought I was getting the hang

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.