gpt4 book ai didi

objective-c - Objective-C 是否保证接口(interface)成员数据的初始化?

转载 作者:太空狗 更新时间:2023-10-30 03:25:09 24 4
gpt4 key购买 nike

在这样的界面中:

@interface MyClass : NSObject
{
bool PlainOldBool;
}

@end

...PlainOldBool 是否自动初始化为 false,或者是否有必要使用 init 方法显式地执行此操作?

最佳答案

是的(unless your false is not 0)。默认的 +alloc/+allocWithZone: 方法将自动清零所有 ivar。

来自 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).

关于objective-c - Objective-C 是否保证接口(interface)成员数据的初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2533209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com