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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:05:06+00:00 2026-06-01T01:05:06+00:00

I encountered a very strange behavior when i m trying to insert a NSMutableDictonary

  • 0

I encountered a very strange behavior when i m trying to insert a NSMutableDictonary into an NSMutableArrey while the app is in a for-loop.

The NSMutableDict is constructed every for-step and added to an array. but it doesnt work… when i print out the array after the for loop, every NSMutableDictonary in the array is the same – After some logging, i saw that every for-step, all dictionarys in the array gets replaced and one is added at the end… thats a strange behavior and i dont know whats causing this…
If i add the currentID (see code) to the array insted of the dictonary, in the end, all looks fine…
whats the problem here?

NSArray *relativeIAbnormality = [[NSArray alloc] init];
NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
NSMutableArray *tempArray = [[NSMutableArray alloc] init];

for (int q = 0; q < [measureData.list count]; q++) {
    [tempDict removeAllObjects];
    NSString *currentId = [[measureData.list objectAtIndex:q] valueForKey:@"id"];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id == %@", currentId];
    NSInteger count = [[lastMeasureData.list filteredArrayUsingPredicate:predicate] count];

    if(count > 0){

        // get the answer Value for the CURRENT measure
        float theValue = 0;
        theValue = [[[[measureData.list objectAtIndex:q] objectForKey:@"propertys"] valueForKey:@"answerValue"] floatValue];

        theValue = theValue/100;

        if(theValue > 10){
            theValue = 10;
        }else if (theValue < 0) {
            theValue = 0;
        }

        // get the answer Value for the LAST measure
        float theNewValue = 0;

        theNewValue = [[[[[lastMeasureData.list filteredArrayUsingPredicate:predicate] objectAtIndex:0] objectForKey:@"propertys"] valueForKey:@"answerValue"] floatValue];

        theNewValue = theNewValue/100;

        if(theNewValue > 10){
            theNewValue = 10;
        }else if (theNewValue < 0) {
            theNewValue = 0;
        }

        // gets the reltaive
        theValue = theValue - theNewValue;
        NSNumber *dif = [NSNumber numberWithFloat:theValue];

        [tempDict setObject:currentId forKey:@"id"];
        [tempDict setObject:dif forKey:@"dif"];

        //NSLog(@"tempDict: %@", tempDict);

        [tempArray addObject:tempDict];
        //NSLog(@"tempArray: %@", tempArray);
    }
}
//NSLog(@"full tempArray: %@", tempArray);
  • 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-01T01:05:08+00:00Added an answer on June 1, 2026 at 1:05 am

    You keep using the very same instance of tempDict. Move that alloc-init pair of your temp-dict inside the loop.

    NSArray *relativeIAbnormality = [[NSArray alloc] init];
    NSMutableArray *tempArray = [[NSMutableArray alloc] init];
    for (int q = 0; q < [measureData.list count]; q++) 
    {
        NSMutableDictionary *tempDict = [[NSMutableDictionary alloc] init];
        ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I've encountered a very strange error while trying to get the contents of
We have encountered a very strange class not found problem in our web app
I have just encountered very strange problem - my GWT app hosted on Google
I have encountered a very strange thing today : I have an app installed
I encountered a very strange behavior in Python, a behavior that is not consistent.
i am relatively new to php and i've encountered a very strange problem. let
I have encountered a very weird situation in Python. I have a while True:
I'm trying to learn python and have encountered some strange behaviour. I am experimenting
I've encountered some very strange behaviour when debugging in VS 2010 with a WCF
I have encountered a very strange issue. Whenever I use the .NET membership provider

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.