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

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

What does this line of code mean?

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

The ? and :

13条回答
  •  别那么骄傲
    2020-11-22 04:24

    That's just the usual ternary operator. If the part before the question mark is true, it evaluates and returns the part before the colon, otherwise it evaluates and returns the part after the colon.

    a?b:c
    

    is like

    if(a)
        b;
    else
        c;
    

提交回复
热议问题