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

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

What does this line of code mean?

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

The ? and :

13条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 04:39

    It's just a short form of writing an if-then-else statement. It means the same as the following code:

    if(inPseudoEditMode)
      label.frame = kLabelIndentedRect;
    else
      label.frame = kLabelRect;
    

提交回复
热议问题