How to print Boolean flag in NSLog?

后端 未结 11 2347
深忆病人
深忆病人 2020-12-02 04:06

Is there a way to print value of Boolean flag in NSLog?

11条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 04:31

    Here's how I do it:

    BOOL flag = YES;
    NSLog(flag ? @"Yes" : @"No");
    

    ?: is the ternary conditional operator of the form:

    condition ? result_if_true : result_if_false
    

    Substitute actual log strings accordingly where appropriate.

提交回复
热议问题