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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:55:20+00:00 2026-05-26T19:55:20+00:00

Take a look at this piece of code – (NSMutableDictionary *)getUsersFromServer { //here we’re

  • 0

Take a look at this piece of code

- (NSMutableDictionary *)getUsersFromServer
{
//here we're getting list of users from the server
NSMutableDictionary * users = [[[NSMutableDictionary alloc] init] autorelease];

userresults = [[NSMutableArray alloc] init];    

//all this will be replaced with users taken from the server. it's needed just for testing
for (int i = 0;i < 19;i++)
{

    int wins    = i ;         float f_wins = (float)wins;
    int losses  = i * 2 ;     float f_losses = (float)losses;
    int withdr  = i * 3 ;     float f_withdr = (float)withdr;
    float win_per = f_wins / ((f_wins + f_losses + f_withdr) / 100.0);

 [userresults setArray:[NSMutableArray arrayWithObjects:[NSNumber numberWithInt:wins],
                                                                                [NSNumber numberWithInt:losses],
                                                                                [NSNumber numberWithInt:withdr],
                                                                                [NSNumber numberWithFloat:win_per],
                                                                                 nil]]; 
[users setObject:userresults forKey:[NSString stringWithFormat:@"user number %i",i]];

}

[userresults release];
return users;
}

in each loop iteration i fill array with numbers and set it as value into NSMutableDictionary. As a key for each array serves formatted string which is unique by number of iteration counter. So… the problem is – the dictionary is always filled with SAME arrays for DIFFERENT keys. There are 19 arrays in the dictionary and ALL THEY ARE LAST ONES!!!! That is from the last iteration. And each one has different key!!! How could it happen??? What’s going on???

  • 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-26T19:55:21+00:00Added an answer on May 26, 2026 at 7:55 pm

    userresults points to the same object, and you’re modifying that same array with the setArray: method. Create a new array in each loop iteration instead:

    NSArray *userData = [NSArray arrayWithObjects:[NSNumber numberWithInt:wins],
                                                  [NSNumber numberWithInt:losses],
                                                  [NSNumber numberWithInt:withdr],
                                                  [NSNumber numberWithFloat:win_per],
                                                  nil];
    [users setObject:userData forKey:[NSString stringWithFormat:@"user number %i",i]];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take a look at this piece of code here: void game::startLoop() { while(QUIT ==
Take a look at this piece of code here: void game::startLoop() { while(QUIT ==
Please take a look at this piece of code. I'm allocating one byte for
Please take a look at this piece of code I came up with. abstract
Take a look at this piece of code The height of the div is
I would really appreciate if you would take a look at this piece of
take a look at this example code: public class Comment { private Comment() {
Take a look at this code: public class Test { public static void main(String...
take a look at this code: $(document).ready(function() { document.getElementById(sliderId).onmousedown = sliderMouseDown; }); function sliderMouseDown()
I have this piece of code right here , I really don't get it

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.