如何管理BOOL变量?

时间:2013-10-20 12:02:23

标签: ios objective-c int boolean

我正在使用变量“volume”

@property BOOL * volume;

设置音量开(是)或关(否)

- (IBAction)manageVolume:(UIButton *)sender {
    if (_volume == TRUE) {
        _volume = !_volume; 
//      code...
    } else {
        _volume = !_volume;
//      code...
        }
    }

它可以工作,但它会返回三个警报:

  • if (_volume == TRUE) {返回Comparison between pointer and integer ('BOOL *' (aka 'signed char *') and 'int')

  • _volume = !_volume;返回Incompatible integer to pointer conversion assigning to 'BOOL *' (aka 'signed char *') from 'int'

我该如何解决?谢谢!

1 个答案:

答案 0 :(得分:16)

您的属性定义错误。它不应该是指向BOOL的指针,它应该只是BOOL

@property BOOL volume;