What values should I use for iOS boolean states?

后端 未结 5 1514
执笔经年
执笔经年 2021-01-04 10:23

It appears that in iOS I have a number of options that seem to fit for boolean values:

YES
NO
TRUE
FALSE
true
false

Which ones should I use

5条回答
  •  温柔的废话
    2021-01-04 11:21

    I share your view on this, whilst they are currently all defined the same, porting the code is a pain when you may find TRUE != true. (Precisely why we should never test X == 1 for TRUE as some languages use -1 and some use 1)

    I think it might be personal preference and mainly about future ports.

    I follow the TRUE and FALSE options so that porting to C/C++ is easier.

    You may find that true and false is better if you're regularly converting code to Java so there's less search/replaces but I found consistency with Cocoa easier.

提交回复
热议问题