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?
Yes (unless your false
is not 0). The default +alloc
/+allocWithZone:
method will automatically zero out all ivars.
From https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/CocoaFundamentals/CocoaObjects/CocoaObjects.html#//apple_ref/doc/uid/TP40002974-CH4-SW17
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With