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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:43:28+00:00 2026-06-01T19:43:28+00:00

in my program i want to add 20 objects to dictionary using for loop

  • 0

in my program i want to add 20 objects to dictionary using for loop so i did

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    self.responseData = nil;

    NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"loans"];
    NSLog(@"%i",[latestLoans count]);

parsedDict = [[NSMutableDictionary alloc] init];


for (int i=0; i<[latestLoans count]; i++) {


    //get latest loan
    NSDictionary* loan = [latestLoans objectAtIndex:i];

    //fetch the data
    NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];
    NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
    float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];

    NSString* name = [loan objectForKey:@"name"];
    NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];

    [parsedDict setObject:fundedAmount forKey:@"funded_amount"];
    [parsedDict setObject:loanAmount forKey:@"loan_amount"];
    [parsedDict setObject:name forKey:@"name"];
    [parsedDict setObject:country forKey:@"location"];
        }
nslog(@"%@",parsedDict);

but when i log it out of the loop i am getting only the last added values..not all the values..

  • 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-01T19:43:29+00:00Added an answer on June 1, 2026 at 7:43 pm

    Use an array to store the records…

      NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
            self.responseData = nil;
    
            NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"loans"];
            NSLog(@"%i",[latestLoans count]);
    
    
         NSMutableArray someArray=[[NSMutableArray alloc]init];
    
        for (int i=0; i<[latestLoans count]; i++) {
    
        parsedDict = [[NSMutableDictionary alloc] init];
            //get latest loan
            NSDictionary* loan = [latestLoans objectAtIndex:i];
    
            //fetch the data
            NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];
            NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
            float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];
    
            NSString* name = [loan objectForKey:@"name"];
            NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];
    
            [parsedDict setObject:fundedAmount forKey:@"funded_amount"];
            [parsedDict setObject:loanAmount forKey:@"loan_amount"];
            [parsedDict setObject:name forKey:@"name"];
            [parsedDict setObject:country forKey:@"location"];
            [someArray addObject:parsedDict];
                }
        NSLog(@"%@",parsedDict);
    
    //Read from Array
    
    
    for(NSDictionary *tempDict in someArray) 
    {
       //use [tempDict objectForKey:@"keyName"] to get values from each dictionary
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to loop through a collection of objects and add them all to
In my program, I draw some quads. I want to add the functionality for
I want to program an Add-Window to my application, much like the Add Contact-window
I want to write a command line program to add a contact to GoogleMail.
I want to create registry key through java program to add the jar file
I want to embed a dictionary.txt which my program uses a streamreader object to
I am using the NetDataContractSerializer. I can create, add and serialize objects into data
I have a diagram designer program and I want to add texts to shapes
In my C program I want to know if my executable is run in
I have a program and want to debug it in gdb. Will I see

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.