E-Madd
E-Madd

Reputation: 4572

Newb ObjC Question re: BOOL property on a class

@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?

Upvotes: 0

Views: 190

Answers (1)

Alex Reynolds
Alex Reynolds

Reputation: 96927

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).

Upvotes: 2

Related Questions