斯坦福老头的课看到第二节,编写计算器时碰到一个问题没想明白,是关于BOOL类型的 userIsInTheMiddleOfEnteringANumber变量 来判断用户是否是输入的第一个数字,这是个自定义的私有方法,用@
property和@
synthesize来合成存取器方法。紧接着下面的if (self.userIsInTheMiddleOfEnteringANumber) 就获取了userIsInTheMiddleOfEnteringANumber中的值来做判断
请问:这个获取的userIsInTheMiddleOfEnteringANumber值从哪里来的,还是BOOL类型的默认了@
property和@
synthesize之后初始值就是NO?
如下:
#import "CalculatorViewController.h"
@
interface CalculatorViewController ()
@
property (nonatomic) BOOL userIsInTheMiddleOfEnteringANumber;
@
end
@
implementation CalculatorViewController
@
synthesize display = _display;
@
synthesize userIsInTheMiddleOfEnteringANumber = _userIsInTheMiddleOfEnteringANumber;
- (IBAction)digipressd:(UIButton *)sender
{
NSString *digit = [sender currentTitle];
if (self.userIsInTheMiddleOfEnteringANumber) {
self.display.text = [self.display.text stringByAppendingString:digit];
}
else {
self.display.text = digit;
self.userIsInTheMiddleOfEnteringANumber = YES;
}
}