Is there any difference between bool, Boolean, and BOOL in Objective-C?

前端 未结 3 2025
栀梦
栀梦 2020-12-28 13:00

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

What is the difference between bool, Boolean and BOOL?

3条回答
  •  时光说笑
    2020-12-28 13:43

    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.

提交回复
热议问题