In an interface such as this:
@interface MyClass : NSObject
{
bool PlainOldBool;
}
@end
... does PlainOldBool
get auto-initialized to false, or is it necessary to use an init method to do that explicitly?
In an interface such as this:
@interface MyClass : NSObject
{
bool PlainOldBool;
}
@end
... does PlainOldBool
get auto-initialized to false, or is it necessary to use an init method to do that explicitly?
Objective-C uses the same rules as C for primitive type auto-initialization. In this case, yes, it would be initialized to false
.
Yes (unless your false
is not 0). The default +allocWithZone:
method will automatically zero out all ivars.
- It initializes all other instance variables to zero (or to the equivalent type for zero, such as
nil
,NULL
, and0.0
).
Also worth noting is that if you're doing Objective-C++, C++ objects that are ivars of Objective-C objects are not initalized : their constructors are not called by default.