Search code examples
objective-cconditional-statementsconditional-operator

Conditional operators in Objective-C


Can we use conditional operators in Objective-C as like in C++. I just tried to implement like this (condition) ? true-statement : false-statement;

 if(page==1)?(buttonPrev.hidden=TRUE):(buttonPrev.hidden=FALSE);

But it results an error "Expected expression".


Solution

  • yes you can use. try like this and don't keep if statement for checking the condition that is the problem in your case.

     (page==1)?(buttonPrev.hidden=TRUE):(buttonPrev.hidden=FALSE);
    

    if you want to assign the value directly then simply use

    buttonPrev.hidden=(page==1)?TRUE:FALSE;