What values should I use for iOS boolean states?该不该使用true和false作为bool值
来源:互联网 发布:jsp导入java类 快捷键 编辑:程序博客网 时间:2024/05/05 06:59
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:
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.
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.
0 0
- What values should I use for iOS boolean states?该不该使用true和false作为bool值
- BOOL,TRUE,FALSE 和 bool ,true, false
- What does AspCompat="true" mean and when should I use it?
- js中Boolean值为false和true的情况:
- What NoSQL Store Should I Use? The Right Tool for Your Use Case
- bool true false
- iOS bool Bool boolean Boolean
- BOOL与bool TRUE与true FALSE与false 区别
- C 语言下 BOOL TRUE FALSE的使用
- c语言中如何使用bool true false
- cout将bool直接输出为true和false
- 如何选择硬盘尺寸?(What size drive should I use?)
- [iOS]BOOL / bool / Boolean / NSCFBoolean
- PL/SQL的BOOLEAN的三个值:TRUE,FALSE,NULL
- what should I do?
- What should i do?
- What should I do?
- What should I do.
- 【数字之魅】寻找最大的K个数(求第k大的数)
- hdoj 5501 The Highest Mark 【贪心 + 0-1背包】
- 第16章 网络IPC:套接字
- 使用 Spring Data JPA 简化 JPA 开发
- java的基本程序设计结构(一)
- What values should I use for iOS boolean states?该不该使用true和false作为bool值
- sicily 1007. To and Fro
- Bellman-Ford-POJ-1860-Currency Exchange
- foreach语句使用总结
- this;static 介绍
- 反应器(Reactor)模式
- $.ajax({...});异步请求问题
- vim查找替换,转载自实验楼
- 关于懒加载的一些小细节