开发者

Newb ObjC Question re: BOOL property on a class

开发者 https://www.devze.com 2023-01-04 01:45 出处:网络
@interface... BOOL nameIsValid; @property (nonatomic) BOOL nameIsValid; @implementation... @sysnthesize nameIsValid;

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

0

精彩评论

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