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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:43:38+00:00 2026-05-18T07:43:38+00:00

It seems like i have a logical problem in this loop. I am trying

  • 0

It seems like i have a logical problem in this loop. I am trying to:

  • Looping myKeys (from a dict) to find selected players
  • Setting three BOOL parameters for the selected players (YES or NO) in an NSMutableArray (thePlayers)
  • Updating a dict (selectedPlayerDict) with ‘thePlayers’ and ‘myKeys’
  • Empty thePlayers and do a new loop and the same thing

The individual players, when i select each player separately has the following parameters:

selectedPlayerDict:{Hannah = (0,0,1);}

selectedPlayerDict: {
AAAXXX = (
1,
1,
1
);
}

When is select both, meaning the trigger on (if ([theObjects objectAtIndex:3] == [NSNumber numberWithBool:YES])), i get the following result with

selectedPlayerDict: {
AAAXXX = (
0,
0,
1,
1,
1,
1
);
Hannah = (
0,
0,
1,
1,
1,
1
);
}

For the result above i use:

//[thePlayers removeAllObjects]; //<<<<<<<<<<<<<<<<<<<<<<<<<<

When i change and remove the commentary “//”:

[thePlayers removeAllObjects]; //<<<<<<<<<<<<<<<<<<<<<<<<<<

I get the following result:

selectedPlayerDict: {
AAAXXX = (
);
Hannah = (
);
}

The code i use is:

for (NSString *myKeys in allTheKeys) {
    theObjects = [playerDict valueForKey:myKeys];

    if ([theObjects objectAtIndex:3] == [NSNumber numberWithBool:YES]) {

        //[thePlayers addObject:myKeys]; 

        NSLog(@"Spelare: %@ är vald", myKeys);
        NSLog(@">>>><<<<");

        // Check what difficulties level
        if ([theObjects objectAtIndex:0] == [NSNumber numberWithBool:YES]) { //hard
            NSLog(@"Player have diff HARD");
            [thePlayers addObject:[NSNumber numberWithBool:YES]]; //@"YES"];
        }
        else {
            NSLog(@"Player have NOT diff HARD");
            [thePlayers addObject:[NSNumber numberWithBool:NO]]; //@"NO"];
        }
        if ([theObjects objectAtIndex:1] == [NSNumber numberWithBool:YES]) { //medium
            NSLog(@"Player have diff MEDIUM");
            [thePlayers addObject:[NSNumber numberWithBool:YES]]; //@"YES"];
        }
        else {
            NSLog(@"Player have NOT diff MEDIUM");
            [thePlayers addObject:[NSNumber numberWithBool:NO]]; //@"NO"];
        }
        if ([theObjects objectAtIndex:2] == [NSNumber numberWithBool:YES]) { //easy
            NSLog(@"Player have diff EASY");
            [thePlayers addObject:[NSNumber numberWithBool:YES]]; //@"YES"];
        }
        else {
            NSLog(@"Player have NOT diff EASY");
            [thePlayers addObject:[NSNumber numberWithBool:NO]]; //@"NO"];
        }
        [selectedPlayerDict setValue:thePlayers forKey:myKeys];
        [thePlayers removeAllObjects];   //<<<<<<<<<<<<<<<<<<<<<<<<<<
    }

}
NSLog(@"selectedPlayerDict: %@", selectedPlayerDict);

I know i probably do something wrong here with the logic but i have tried now for hours to try to understand what i am doing wrong. I do not understand why the dic’s objects is empty as i am “removeAllObjects” in the array in the end of the loop after i have updated the dict? I have tried “setObject:forKey:” but with no luck.

  • 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-18T07:43:38+00:00Added an answer on May 18, 2026 at 7:43 am

    The problem is that you are reusing the same array for every key in selectedPlayerDict. You would need to create a fresh array for each loop iteration; otherwise, the removeAllObjects is removing all objects from the single array that is the value for every key in your dictionary.

    As a side note, I wonder if an enum {Easy, Medium, Hard}; might serve your need better than 3 BOOLs — what will happen if the user selects > 1 of the options?

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

Sidebar

Related Questions

Seems like a simple problem: I have an SVN repo inside our firewall. I
I have a problem that seems like its a result of a deadlock-situation. Whe
This seems like a pretty softball question, but I always have a hard time
Anybody have a slicker way to do this? Seems like it should be easier
It seems like when you have a WinForms .NET application, and a ComboBox (set
I have tried what seems like everything - I've done similiar things many times
It seems like I will be needing transaction with MySQL and I have no
I have been looking through Scott Guthrie's MVC tutorials and it seems like the
I have checked with the wikipedia article , and it seems like it is
Why do PHP regexes have the surrounding delimiters? It seems like it would be

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.