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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:43:54+00:00 2026-05-27T22:43:54+00:00

I have two NSMutableArrays. The content of the first is numerically, which is paired

  • 0

I have two NSMutableArrays. The content of the first is numerically, which is paired to the content of the second one:

First Array    Second Array
   45              Test45
   3               Test3
   1               Test1
   10              Test10
   20              Test20

That’s the look of both arrays. Now how could I order them so numerically so they end up like:

First Array    Second Array
   1               Test1
   3               Test3
   10              Test10
   20              Test20
   45              Test45

Thanks!

  • 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-27T22:43:55+00:00Added an answer on May 27, 2026 at 10:43 pm

    I would put the two arrays into a dictionary as keys and values. Then you can sort the first array (acting as keys in the dictionary) and quickly access the dictionary’s values in the same order. Note that this will only work if the objects in the first array support NSCopying because that’s how NSDictionary works.

    The following code should do it. It’s actually quite short because NSDictionary offers some nice convenience methods.

    // Put the two arrays into a dictionary as keys and values
    NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:secondArray forKeys:firstArray];
    // Sort the first array
    NSArray *sortedFirstArray = [[dictionary allKeys] sortedArrayUsingSelector:@selector(compare:)];
    // Sort the second array based on the sorted first array
    NSArray *sortedSecondArray = [dictionary objectsForKeys:sortedFirstArray notFoundMarker:[NSNull null]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes (MVC view model) which inherits from one abstract base class.
I have two functions which one should i use? Please explain the difference. A:
I have Two NSMutableArray .My First Array contain 3 UIButtons along With Buttons Titles
I have a method that accepts three NSMutableArrays, one as Input and two as
I have two array one is NSMutableArray and one is NSArray i want to
I have two viewControllers and one has to pass an array to another, but
I have two NSMutabeArrays, one full of numbers, the other full of words. Lets
Have two actionsheet buttons and one modalviewcontroller on mainviewcontroller in application. Now for two
I have two NSMutableArrays: NSMutableArray* currentMessages NSMutableArray* items I am trying to copy the
I've got a simple object post that has two NSMutableArrays as properties. One is

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.