gpt4 book ai didi

objective-c - 如果我写一个 @synthesize 语句,我会得到与属性同名但没有下划线的 ivar 吗?

转载 作者:行者123 更新时间:2023-12-01 22:29:37 25 4
gpt4 key购买 nike

只是根据问题标题,我知道如果我要省略 @synthesize 语句,我会得到一个具有相同属性名称和前面的下划线的 ivar。那么,如果我在语句中手动编写 @synthesize,我会得到与属性同名但没有下划线的 ivar 吗?

其次,作为一个相关问题,您通常会建议在您的 ivar 前面加上下划线吗?我应该如何考虑这里的最佳实践?

非常感谢您的帮助。

最佳答案

if I manually write the @synthesize in a statement I will instead get the ivar with the same name as the property, but without the underscore

是的,你会的(尽管有一个更完整的 @synthesize 形式可以让你state你想要的名字)。

how should I think about best practice here

下划线是最佳实践;这就是为什么当你声明一个属性时它是你自动得到的。这样,您就可以防止意外遮盖阴影。如果它们都具有相同的名称,例如 myVar,那么您可以说 self.myVarmyVar 它们是完全不同的东西,这是对麻烦的邀请。

关于objective-c - 如果我写一个 @synthesize 语句,我会得到与属性同名但没有下划线的 ivar 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30133040/

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