Search code examples
cocoabooleanquartz-composer

QCView inputKey responds to NO but crashes on YES


I have a QCView with a boolean input splitter in it. When I try and do [qcview setValue:NO forInputKey:@"showCube"]; it works as expected and the input gets set to NO. However, When I try and do [qcview setValue:YES forInputKey:@"showCube"]; I get EXC_BAD_ACCESS. I have tried using 1, YES, and TRUE and they all give the same error. Whet could be the issue causing this mysterious error?

Thanks


Solution

  • setValue:forInputKey: expects value to be an object (not a scalar, which you're supplying).

    Try

     [qcview setValue:[NSNumber numberWithBool:YES] forInputKey:@"showCube"];
    

    or

     [qcview setValue:kCFBooleanTrue forInputKey:@"showCube"];
    

    (A standalone scalar NO works in this case, since it evaluates to 0, equivalent to nil in Objective-C, which, under some circumstances, can receive messages without exploding. But really you should be using either the NSNumber constructor, or one of the Core Foundation constants.)