What is the default value of a BOOL
variable in Objective-C?
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).)