如何更改BOOL的值?

时间:2012-12-20 01:45:58

标签: objective-c xcode boolean logic

如何在Objective-C中更改BOOL的值? lightOn是我需要帮助修改的BOOL值。

@synthesize button, view;
-(IBAction)torchOn:(id)sender;
     {
          AVCaptureDevice*flashlight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if([flashlight isTorchAvailable] && [flashlight isTorchModeSupported:AVCaptureTorchModeOn] && [lightOn = YES])
{
    BOOL success  [[flashlight lockForConfiguration:nil]];
    if(success)
    {
        [flashlight setTorchMode:AVCaptureTorchModeOn];
        [flashlight unlockForConfiguration];
        lightOn = NO;
    }
}

}

2 个答案:

答案 0 :(得分:2)

Objective-C扩展了ANSI C语言。开始在那里学习。 Here's a primer

BOOL amICrazy;

amICrazy = YES;
// amICrazy = NO;
if (amICrazy == YES)
    [self seekHelp];

答案 1 :(得分:2)

BOOL success [[flashlight lockForConfiguration:nil]];是毫无意义的陈述。

即使我将[[flashlight lockForConfiguration:nil]]视为[flashlight lockForConfiguration:nil],但lockForConfiguration:方法应返回BOOL值。

然后可以通过以下方式将该值分配给成功:

BOOL success = [flashlight lockForConfiguration:nil];