Default value of BOOL

前端 未结 2 2107
野性不改
野性不改 2020-12-02 16:15

What is the default value of a BOOL variable in Objective-C?

2条回答
  •  生来不讨喜
    2020-12-02 17:06

    There is no default value if you write

    -(void)somemethod {
      BOOL x;  // <--- no default value
    

    It is initialized to garbage.

    However, for a BOOL ivar, it will be initialized to NO, as the whole instance is filled with 0 on initialization.

    (Note: When ARC is enabled, local object pointers will always be have a default value nil, but local variables of non-object types like BOOL are still initialized to garbage. See Local variables set to nil? (Objective-C).)

提交回复
热议问题