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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:37:43+00:00 2026-06-06T13:37:43+00:00

I have a NSMutableArray of objects, below is the struct: //object at index i

  • 0

I have a NSMutableArray of objects, below is the struct:

//object at index i
locations {
   NSString* address;
   NSString* state;
   NSNumber* distance;
}

I have 10000 object like the above structure in the NSMutableArray.
How do order this array so that the locations are in order by the NSNumber distance?

I tried this:

lowToHigh = [NSSortDescriptor sortDescriptorWithKey:@"distance" ascending:YES];
[locationArray sortUsingDescriptors:[NSArray arrayWithObject:lowToHigh]];

is using the sortDescriptorWithKey:@"distance" wrong? since distance isn’t actually a key, it NSNumber* distance.

edit in my header @property (strong, nonatomic)NSNumber* _distance; and then @synthesize _distance = distance; in my methods file but this is in locationObjects.* object class. Then I import this in my current class I am doing this sorting. Is that an issue?
How I import is locationObjects* locObj = [[locationObjects alloc] init];

  • 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-06T13:37:44+00:00Added an answer on June 6, 2026 at 1:37 pm

    This is what I use:

    NSSortDescriptor *lowToHigh = [[NSSortDescriptor alloc] initWithKey:@"distance"
                                                  ascending:YES];
    NSArray *mySortDescriptors = [NSArray arrayWithObject:lowToHigh];
    NSArray *sortedArray = [locationArray sortedArrayUsingDescriptors:mySortDescriptors];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a NSMutableArray of QuoteMap objects. When I add one using the below
I have an NSMutableArray of NSString objects. How would I make an NSString that
I have an events object which is given below NSString *name; NSString *date; NSInteger
I have a NSMutableArray with many objects. Can i extract a subarray from index
I have a Card Object, which have 4 instance variables namely name(NSString), pin(NSString), points(NSNumber),
I have an NSMutableArray that is populated with objects of strings. For simplicity sake
I've got NSMutableArray with objects Link which has parameter Byte taskOne . I have
I have two simple NSMutableArray that consists of few objects. Some of these objects
Say I have an object someObject and an NSMutableArray *someArray . I'm not sure
I have NSMutableArray with different objects in it of different classes. Now I want

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.