I have an NSMutableSet that I am trying to add labels to. After each label added, I check the set's count and it comes back as 0. Any help will be appreciated
In my .h file:
@interface MainMenu : CCLayerColor {
NSMutableSet* letters;
}
In my .m file:
-(void)initiateLetters{
//Grab the window size
CGSize size = [[CCDirector sharedDirector] winSize];
int i;
for(i=0;i<100;i++){
CCLabelTTF *label;
int r = rand() % 35 + 60;
char c = (char) r;
label = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%c",c] fontName:@"Courier" fontSize:30];
[label setColor:ccc3(0,0,0)];
[label setOpacity:255/2];
//Generate a random number for the x variable, y will be 0
int x = (arc4random() % (int)size.width);
int y = size.height+(arc4random() % 50)+25;
[label setPosition:ccp(x,y)];
[self addChild:label];
[letters addObject:label];
//Here's what's printing 0:
printf("%lu",[letters count]);
}
}
You have to instantiate the set before you can add things to it. You can do that in an overridden implementation of
init
:…or at the beginning of your
initiateLetters
method:Instead, the code you posted is simply sending
addObject:
tonil
, which does nothing.