我应该使用什么样的价值观适用于iOS布尔状态? [英] What values should I use for iOS boolean states?
问题描述
目前看来,在iOS的我有许多选项,似乎适合布尔值:
It appears that in iOS I have a number of options that seem to fit for boolean values:
YES
NO
TRUE
FALSE
true
false
我应该使用哪一个?在这种特殊情况下,我躲在一个标签,所以我应该在隐藏
属性设置为是
, TRUE
或真正
?
推荐答案
简短的回答:你应该preFER 是
和 NO
设置类型的基础属性 BOOL
。
Short answer: you should prefer YES
and NO
for setting foundation properties of type BOOL
.
对于长的答案,让我们先看看在哪里这些常量定义的:
For the long answer, let's first see where are these constants defined:
-
真正
和假
从<一个href=\"http://pubs.opengroup.org/onlinepubs/007904875/basedefs/stdbool.h.html\"><$c$c>stdbool.h$c$c>;他们是的#define
-d为1
和0
-
TRUE
和FALSE
从CFBase.h
;他们是的#define
-d为1
和0
-
是
和NO
从NSObjCRuntime.h
。这是符号字符
是的typedef
-ed为BOOL
和它的两个值的#define
-d为((BOOL)1)
和((BOOL)0)
或__ objc_yes
/__ objc_no
如果objc_bool
是支持的。
true
andfalse
are fromstdbool.h
; they are#define
-d as1
and0
TRUE
andFALSE
are fromCFBase.h
; they are#define
-d as1
and0
YES
andNO
are fromNSObjCRuntime.h
. This is wheresigned char
istypedef
-ed asBOOL
, and its two values are#define
-d as((BOOL)1)
and((BOOL)0)
or__objc_yes
/__objc_no
ifobjc_bool
is supported.
基础类坚持使用 BOOL
,这是一个的typedef
为符号字符
,重新present它的布尔属性。由于前两对地转化为 INT
常量,使用它们可能导致警告,尽管它可能会正常工作呢。在是
和 NO
常量,然而,在你的编译器最兼容的方式定义,无论其版本。因此,我建议使用是
和 NO
始终在您的code。
The foundation classes consistently use BOOL
, which is a typedef
for signed char
, to represent its boolean properties. Since the first two pairs get converted to int
constants, using them may result in warnings, though it would probably work correctly anyway. The YES
and NO
constants, however, are defined in the most compatible way for your compiler, regardless of its version. Therefore, I would recommend using YES
and NO
consistently throughout your code.
这篇关于我应该使用什么样的价值观适用于iOS布尔状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!