我应该使用什么样的价值观适用于iOS布尔状态? [英] What values should I use for iOS boolean states?

查看:106
本文介绍了我应该使用什么样的价值观适用于iOS布尔状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前看来,在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;他们是的#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 and false are from stdbool.h; they are #define-d as 1 and 0
  • TRUE and FALSE are from CFBase.h; they are #define-d as 1 and 0
  • YES and NO are from NSObjCRuntime.h. This is where signed char is typedef-ed as BOOL, and its two values are #define-d as ((BOOL)1) and ((BOOL)0) or __objc_yes/__objc_no if objc_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆