Newb ObjC Question re: BOOL property on a class
@interface...
BOOL nameIsValid;
@property (nonatomic) BOOL nameIsValid;
@implementation...
@sysnthesize nameIsValid;
-(void)someMetho开发者_如何学Cd {
nameIsValid = YES;
}
-(void)anotherMethod {
if(nameIsValid){
...
}
}
Why does my if statement always evaluate to FALSE, even after the someMethod is called?
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
).
精彩评论