Objective-C是否保证接口成员数据的初始化? [英] Does Objective-C guarantee the initialization of interface member data?

查看:92
本文介绍了Objective-C是否保证接口成员数据的初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这样的界面中:

@interface MyClass : NSObject
{
    bool PlainOldBool;
}

@end

... PlainOldBool是否会自动初始化为false,还是必须使用init方法来显式地做到这一点?

... does PlainOldBool get auto-initialized to false, or is it necessary to use an init method to do that explicitly?

推荐答案

是(除非您的false是不是0 ).默认的+alloc/+allocWithZone:方法将自动将所有ivars归零.

Yes (unless your false is not 0). The default +alloc/+allocWithZone: method will automatically zero out all ivars.

来自

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆