Does Objective-C guarantee the initialization of interface member data?

前端 未结 2 1159
不思量自难忘°
不思量自难忘° 2020-12-19 02:29

In an interface such as this:

@interface MyClass : NSObject
{
    bool PlainOldBool;
}

@end

... does PlainOldBool get auto-in

相关标签:
2条回答
  • 2020-12-19 03:10

    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.

    0 讨论(0)
  • 2020-12-19 03:11

    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, and 0.0).
    0 讨论(0)
提交回复
热议问题