What does the question mark and the colon (?: ternary operator) mean in objective-c?

前端 未结 13 2417
南旧
南旧 2020-11-22 04:10

What does this line of code mean?

label.frame = (inPseudoEditMode) ? kLabelIndentedRect : kLabelRect;

The ? and :

13条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-22 04:18

    It is ternary operator, like an if/else statement.

    if(a > b) {
    what to do;
    }
    else {
    what to do;
    }
    

    In ternary operator it is like that: condition ? what to do if condition is true : what to do if it is false;

    (a > b) ? what to do if true : what to do if false;
    

提交回复
热议问题