gpt4 book ai didi

ios - Objective-C参数中前缀 "_"是什么意思

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:58:43 24 4
gpt4 key购买 nike

<分区>

我已经玩 iOS 几个月了,总是使用@synthesize 来“制作 setter 和 getter”@property。但是在一些教程中,我经常看到@synthesize param = _param,我不太明白它的意思。

For example: in .h file

@property (nonatomic, retain) NSString *param1;
@property (nonatomic, retain) NSString *param2;

in .m file

@synthesize param1; //this is what I like to do
@synthesize param2 = _param2; // this is what 'experienced' programmer does

根据我的习惯,我可以使用self.param1,或者只是param1来获取这个实例,顺便问一下有什么区别吗?

从其他人看来,他们似乎喜欢使用 _param2 而不是其他方法。我知道它与getter/setter有关,但我还是不太清楚。

谁能解释一下他们的区别和优缺点?

非常感谢。

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