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

前端 未结 2 1161
不思量自难忘°
不思量自难忘° 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: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).

提交回复
热议问题