Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?

2023-10-05移动开发问题
34

本文介绍了Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我知道 BOOL 实际上是有符号字符的 typedef,但是 Boolean 呢?

bool、Boolean 和 BOOL 有什么区别?

解决方案

Boolean 是一个旧的 Carbon 关键字(历史 Mac 类型),定义为 unsigned char.BOOL 是一种Objective-C 类型,定义为signed char.bool_Bool 标准 C 类型的定义版本.它被定义为一个int.使用 BOOL.

编辑(2019 年):Apple 在一些 BOOL 的底层实现">新文档.基本上,在 macOS 上,BOOL 最终还是一个 signed char,但在 iOS 和相关平台上,它是一个原生的 C bool 下面.p>

I know BOOL is actually a typedef of signed char, but what about Boolean?

What is the difference between bool, Boolean and BOOL?

解决方案

Boolean is an old Carbon keyword (historic Mac type), defined as an unsigned char. BOOL is an Objective-C type defined as signed char. bool is a defined version of the _Bool standard C type. It's defined as an int. Use BOOL.

Edit (2019): Apple talks about the underlying implementation of BOOL in some new documentation. Basically, on macOS, BOOL is still ultimately a signed char, but on iOS and related platforms, it a native C bool underneath.

这篇关于Objective-C 中的 bool、Boolean 和 BOOL 之间有什么区别吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

Cocos2d - 如何检查不同层中对象之间的交集
Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)...
2024-08-12 移动开发问题
8

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

如何将 32 位 PNG 转换为 RGB565?
How to convert 32 bit PNG to RGB565?(如何将 32 位 PNG 转换为 RGB565?)...
2024-08-12 移动开发问题
21

正确的 cocos2d 场景重启?
Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)...
2024-08-12 移动开发问题
7