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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:51:15+00:00 2026-06-13T23:51:15+00:00

In my app, I have a dictionary with two array like: NSDictionary *d=[[NSDictionary alloc]initWithObjectsAndKeys:listOfEvents,@l,arr_distance,@d,

  • 0

In my app, I have a dictionary with two array like:

NSDictionary *d=[[NSDictionary alloc]initWithObjectsAndKeys:listOfEvents,@"l",arr_distance,@"d", nil];
        NSLog(@"%@",d);


 d =     (
    "353.90",
    "354.68",
    "350.42",
    "1.18"
);
l =     (
            {
        Contestant1 = "Jon jones";
        Contestant2 = "Anderson silva";
           },
         {
        Contestant1 = "Jon jones";
        Contestant2 = "Anderson silva";
           },
      {
        Contestant1 = "Jon jones";
        Contestant2 = "Anderson silva";
           },
      {
        Contestant1 = "Jon jones";
        Contestant2 = "Anderson silva";
           }
); 
}

I want to sort the dictionary with first array and when the index changes , the second array index also changed according to it.

Both arrays index are related to each other.

@ABC your tried code

NSDictionary *dict = [NSDictionary dictionaryWithObjects:listOfEvents  forKeys:arr_distance];
        NSArray *sortedArray = [arr_distance sortedArrayUsingSelector:@selector(compare:)];
        NSMutableArray *sortedValues = [NSMutableArray array];

    for (NSString *key in sortedArray) {
        [sortedValues addObject:[dict valueForKey:key]];
    }

    NSLog(@"%@",sortedValues);

Result:

{
1.18,2563.91,2563.41,2563.39,350,353,354}

  • 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-13T23:51:17+00:00Added an answer on June 13, 2026 at 11:51 pm

    Here is one way to do it,

        NSArray *a = [NSArray arrayWithObjects:@"8", @"2", @"4", nil];
        NSArray *b = [NSArray arrayWithObjects:@"val1", @"val2", @"val3", nil];//This can be an array of any objects
    

    or

    a = ["353.90", "354.68", "350.42", "1.18"];
    b = [{
            Contestant1 = "Jon jones";
            Contestant2 = "Anderson silva";
               },
             {
            Contestant1 = "Jon jones";
            Contestant2 = "Anderson silva";
               },
          {
            Contestant1 = "Jon jones";
            Contestant2 = "Anderson silva";
               },
          {
            Contestant1 = "Jon jones";
            Contestant2 = "Anderson silva";
           }];
    

    Do it like this,

        NSDictionary *dict = [NSDictionary dictionaryWithObjects:b forKeys:a];
        NSArray *sortedArray = [a sortedArrayUsingComparator:^(id firstObject, id secondObject) {
            return [((NSString *)firstObject) compare:((NSString *)secondObject) options:NSNumericSearch];
        }];
        NSMutableArray *sortedValues = [NSMutableArray array];
    
        for (NSString *key in sortedArray) {
            [sortedValues addObject:[dict valueForKey:key]];
        }
    
        NSLog(@"%@",sortedValues);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In an app I have a plist : root ---> dictionary cell ----> array
I have an app that is acting like a dictionary and now I need
My app have a background image that fills the screen. I'd like to display
in my app I have no problem withs saving/retrieving string values(like myTextField.text ) into
We're developing a Windows Phone 7 app and have a TextBlock defined like so:
I am working on a dictionary for my class. I have an int array
I have two string properties setup in my cocoa application's app delegate which are
I have two animations defined in my silverlight app : <Storyboard x:Name=ShowControls> <DoubleAnimation Duration=0:0:0.2
i am making an app that will have a very large dictionary of words
my app have action bar on top of windows. Where are some buttons. Buttons

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.