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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:39:32+00:00 2026-06-14T10:39:32+00:00

Goal: Combine all NSDictionaries returned with one common key value ‘delay’ into a single

  • 0

Goal: Combine all NSDictionaries returned with one common key value ‘delay’ into a single NSMutablearry that I can use to compare the results (true or false) to place either a green or red pin on a map.
This code brings back the airport data in JSON that I convert to a dictionary of the requested airports. There are a number of keys, but in this part of the code I am only interested in one – ‘delay’ that I want to combine into one NSMutablearry.
Because I can only request one airport at a time, it brings back each requested airport individually and I get 9 sets of data. What I want is the 9 delay keys all in one array for the 9 different airports.

`- (void)configureData
{

self.airportCodes = [[NSArray alloc] initWithObjects:

                     @"ATL",
                     @"BOS",
                     @"BWI",
                     @"CLT",
                     @"CVG",
                     @"DEN",
                     @"EWR",
                     @"ORD",
                     @"SFO",
                     nil];

NSUInteger airportCount = self.airportCodes.count;


for(int i=0; i < airportCount;i++){

    NSURL *url = [self urlWithSearchText:[self.airportCodes objectAtIndex: i]];
    NSString *jsonString = [self performAirportRequestWithURL:url];
    if (jsonString == nil) {
        [self showNetworkError];

    }


    NSDictionary *dictionary = [self parseJSON:jsonString];
    if (dictionary == nil) {
        [self showNetworkError];
    }

    self.airportDelays = [[NSMutableArray alloc] initWithCapacity:9];


    [self parseDelay:dictionary];

    //NSLog(@"AP Delays %@",self.airportDelays);
} 

return;
}


-  (void)parseDelay:(NSDictionary *)dictionary
{


//self.delay = [dictionary objectForKey:@"delay"];
[self.airportDelays addObject:dictionary];



NSLog(@"AP Delays %@",self.airportDelays);

return;
}

- (NSURL *)urlWithSearchText:(NSString *)searchText
{
NSString *escapedSearchText = 
[searchText    stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *urlString = 
[NSString stringWithFormat:
@"http://services.faa.gov/airport/status/%@? format=application/json", escapedSearchText];
NSURL *url = [NSURL URLWithString:urlString];
return url;
}

- (NSString *)performAirportRequestWithURL:(NSURL *)url
{
NSError *error;
NSString *resultString = [NSString stringWithContentsOfURL:
url encoding:NSUTF8StringEncoding error:&error];
if (resultString == nil) {
    NSLog(@"Download Error: %@", error);
    return nil;
}
return resultString;
}

- (void)showNetworkError
{
UIAlertView *alertView = [[UIAlertView alloc]
                          initWithTitle:@"Whoops..."
                          message:@"There was an error reading 
                          from the FAA Server. Please      try again."
                          delegate:nil
                          cancelButtonTitle:@"OK"
                          otherButtonTitles:nil];
[alertView show];
}


- (NSDictionary *)parseJSON:(NSString *)jsonString
{
NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];

NSError *error;
id resultObject = [NSJSONSerialization JSONObjectWithData:data options:
kNilOptions     error:&error];
if (resultObject == nil) {
    NSLog(@"JSON Error: %@", error);
    return nil;

    if (![resultObject isKindOfClass:[NSDictionary class]]) {
        NSLog(@"JSON Error: Expected dictionary");
        return nil;
    }
}
return resultObject;
}

@end`
  • 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-14T10:39:34+00:00Added an answer on June 14, 2026 at 10:39 am

    Here is your issue: You are instantiating the airportDelays array every time a new dictionary is created, therefore, you are only adding one dictionary before destroying the airportDelay array and creating a new one. See below

    self.airportDelays = [[NSMutableArray alloc] initWithCapacity:9];
    
    
    [self parseDelay:dictionary];
    

    Should be

    if (!self.airportDelays) {
        self.airportDelays = [[NSMutableArray alloc] initWithCapacity:9];
    }
    [self parseDelay:dictionary];
    

    I’m also weary of you using a for loop to do your network operations. You should probably be using a different queueing mechanism, where the program waits for the response for the first dictionary before asking the webservice for the next. That might be a different lesson for a different time though.

    Good luck

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to combine 11 different data types into a single list that I
Given a directed graph, the goal is to combine the node with the nodes
I'm trying to combine a static hard coded string with one referenced from strings.xml
I want to set up a single virtual host that can dynamically handle all
Basically I'm looking to select both string columns and put it all into a
So the goal is to combine two arrays that contain sentences, in a new
My goal is to create a single object in powershell that shows the AD
Goal: Combine two column named first and lastname, from the same table A and
I know this sound very simple, but I failed to combine two strings into
Goal : I wants when I drag image it become fade so we can

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.