开发者

Having a problem with simple bool

I've some really simple code that checks if my bool is == YES but it does not ever enter.

NSLog(@"boool %d",self.arrayAlr开发者_运维百科eadyPopulated );

if (self.arrayAlreadyPopulated == YES) 
{
Match *aMatch = [appDelegate.matchScoresArray objectAtIndex:(numMatchCounter)];
aMatch.teamName1 = TeamNameHolder;
}
else 
{

Match *aMatch = [[Match alloc] init];
aMatch.teamName1 = TeamNameHolder;
    [appDelegate.matchScoresArray addObject:aMatch];
[aMatch release];
}

The debug at the top says that the value of self.arrayAlreadyPopulated is 1 on the 2nd pass as it should be.

But it never enters the first first part but jumps down to the 'else'

I cant see for the life of me what the problem is. -.-

Anybody able to clue me in?

Thanks -Code

EDIT declaration code

BOOL arrayAlreadyPopulated;
@property (nonatomic) BOOL arrayAlreadyPopulated;

@synthesize arrayAlreadyPopulated;


Don't compare a BOOL against YES or NO. They can carry values that are not NO but don't compare equal to YES. Instead, use the boolean expression directly in the if statement:

if (self.arrayAlreadyPopulated)
{
    // ...
}


arrayAlreadyPopulated is probably not actually a BOOL. If, for example, it was a float, the %d would still print 1.


Check and double check that you're assigning the value to arrayAlreadyPopulated always as self.arrayAlreadyPopulated = YES instead of just arrayAlreadyPopulated = YES.

Sometimes, using the property v/s the associated variable of the property interchangeably doesn't always work out the way you'd expect it to. Use the "variable" name only if you're using it to release memory by [variable release] statement, just the way you'll find it in any Apple example code. In all other cases use self.propertyname.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜