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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:52:57+00:00 2026-06-04T22:52:57+00:00

I have made a NSDictionary HospitalDictionary which holds latitude,longitude and distances NSMutableArray *HospitalArray =

  • 0

I have made a NSDictionary HospitalDictionary which holds latitude,longitude and distances

NSMutableArray *HospitalArray = [NSMutableArray array];
NSDictionary *HospitalDictionary = [[NSDictionary alloc]init];

NSString *LATITUDE = @"latitude";
NSString *LONGITUDE = @"longitude";
NSString *DISTANCE = @"distance";

for (int i=0; i<=100; i++) { 
// calculations for coordinates and distance are done ....
HospitalDictionary = [NSDictionary dictionaryWithObjectsAndKeys:latitude, LATITUDE,
        longitude, LONGITUDE,[NSNumber numberWithInt:distanceInKm], DISTANCE, nil];

[HospitalArray addObject:HospitalDictionary];
{ 

Then data is short using following code

// These line are added to short the Dictionary added to Array List with the Key of Distance 
    NSSortDescriptor *distanceDescriptor = [[NSSortDescriptor alloc] initWithKey:DISTANCE ascending:YES];
    id obj;
    NSEnumerator * enumerator = [HospitalArray objectEnumerator];
    NSArray *descriptors = [NSArray arrayWithObjects:distanceDescriptor, nil];
    NSArray *sortedArray = [HospitalArray sortedArrayUsingDescriptors:descriptors];

    enumerator = [sortedArray objectEnumerator];
    // this will print out the shorted list for DISTANCE
    while ((obj = [enumerator nextObject])) NSLog(@"%@", obj);

    // this will return the object at index 1 
    NSLog(@"Selected array is %@",[sortedArray objectAtIndex:1]);

Output of this is –

2012-05-30 08:24:42.784 Hospitals[422:15803] 
sorted array is 
{
    distance = 1;
    latitude = "27.736221";
    longitude = "85.330095";
}

I want to get only Latitude or Longitude for the ObjectAtIndex:1 for the sortedArray. How can i get the particular value ie. latitude out of sortedArray not the complete list.

  • 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-04T22:52:58+00:00Added an answer on June 4, 2026 at 10:52 pm

    To access a property/method of an object in an array, you can use something like this:

    NSLog(@"Latitude for object at index 1 is %@",[[sortedArray objectAtIndex:1] latitude]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a singleton class with a nsmutablearray - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change
I have made a game which is nearly identical to Popcap's Atomica. ( http://www.popcap.com/gamepopup.php?theGame=atomica
I have made a basic ascx control which is just a panel with a
I have a NSDictionary made up of the daily trend from twitter (made up
I've made a UITableView with cells which have different height. On each cell, I've
I have made an app that starts a service, which starts a timer, which
I have made an application (for my self) for feeds reading, using SyndicationFeed ,
I have made a multiplayer game using the GameKit Framework where 2 iPhones/iPods can
I have made a kind of Video Slider, where thumbnail of videos are displaying
I have made a generic Observer interface and an Observable class, but can't compile

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.