开发者

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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜