Note that there are some explanatory texts on larger screens.

plurals
  1. PONSMutableArray won't add NSDictionary
    primarykey
    data
    text
    <p>I updated to cocos2d from 0.99.4 to 0.99.5. While it was on the older version I had the high score list working and I was able to add the NSDictionary to NSMutableArray with no problems. </p> <p>Now that I've updated it won't add the NSDictionary variable scoreDetails to my NSMutableArray scoreList. Here's my code:</p> <p>StatsManager.h</p> <pre><code>@interface StatsManager : NSObject { NSMutableArray *scoreList; NSUserDefaults *saveHighScore; NSMutableArray *printableScoreList; //NSMutableArray *scoreListTestOne; float highScoreHelloWorld; } </code></pre> <p>StatsManager.m</p> <pre><code>-(void)setHighScore:(float)highScore nameStrings:(NSString*)nameString { NSNumber *newHighScore = [NSNumber numberWithFloat:highScore]; NSLog(@"%@ highScore", newHighScore); NSDictionary *scoreDetails = [NSDictionary dictionaryWithObjectsAndKeys:nameString, @"name", newHighScore, @"score", nil]; NSLog(@"%@", scoreDetails); //NSMutableArray *testTwo = [[NSMutableArray alloc] init]; [scoreList addObject:scoreDetails]; NSLog(@"scoreList %@", scoreList); //[scoreListTestOne addObject:scoreDetails]; //NSLog(@"scoreListTestOne %@", scoreListTestOne); //sort NSSortDescriptor *sort = [[NSSortDescriptor alloc] initWithKey:@"score" ascending:NO]; [scoreList sortUsingDescriptors:[NSArray arrayWithObject:sort]]; printableScoreList = scoreList; NSLog(@"printableScoreList %@", printableScoreList); //NSLog(@"scoreListTestOne %@", scoreListTestOne); } </code></pre> <p>The line in question is</p> <pre><code> [scoreList addObject:scoreDetails]; </code></pre> <p>I created a local NSMutableArray variable in the setHighScore function and tried adding the scoreDetails to that and it worked. but why doesn't it work like I've coded it above anymore?</p> <p>I alloc init my scoreList here:</p> <pre><code>@implementation StatsManager static StatsManager *_sharedStatsManager = nil; -(id)init { scoreList = [[NSMutableArray alloc] init]; //playerNames = [[NSMutableArray alloc] init]; //playerScores = [[NSMutableArray alloc] init]; printableScoreList = [[NSMutableArray alloc] init]; //listOfScoresTest = [[NSMutableDictionary alloc] initWithCapacity:5]; /*if ([scoreList count] == 0) { for (int i = 0; i &lt; 5; i++) { [scoreList addObject:[NSNumber numberWithFloat:0.00]]; } }*/ return [super init]; } </code></pre> <p>I should also mention that I created a new projectB and transferred my files/images from my old projectA to the new one because the old one wouldn't compile anymore because of some duplicate error. But i "cleaned all targets" again and it worked but that also has the same problem as my new projectB</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload