views:

49

answers:

1

@interface...

BOOL nameIsValid;

@property (nonatomic) BOOL nameIsValid;

@implementation...

@sysnthesize nameIsValid;

-(void)someMethod {
    nameIsValid = YES;
}

-(void)anotherMethod {
    if(nameIsValid){
       ...
    }
}

Why does my if statement always evaluate to FALSE, even after the someMethod is called?

+2  A: 

Use self.propertyName = value, instead.

Why: Using the self prefix with a left-hand side property calls its synthesized setter method.

If you don't use the setter, then the default value of the BOOL will remain NO (or 0).

Alex Reynolds
Thanks, but that made no difference. Is there anything else that could be wrong?
E-Madd
Nevermind - it was a really stupid error on my part.
E-Madd