gpt4 book ai didi

ios - 以下状态有什么区别?

转载 作者:行者123 更新时间:2023-11-28 19:09:12 25 4
gpt4 key购买 nike

也许这是一个有点幼稚的问题,但我真的很想知道细节。我刚刚看到这段代码:

@implementation SimpleMainViewController
{
SimpleTableViewController *simpleTableViewController;
AboutViewController *aboutViewController;
}

这个和下面那个有什么区别?

@interface SimpleMainViewController : UIViewController
@property(nonatomic,retain) SimpleTableViewController *simpleTableViewController;
@property(nonatomic,retain) AboutViewController *aboutViewController;

@implementation SimpleMainViewController
@synthesize simpleTableViewController;
@synthesize aboutViewController;

感谢转发。

最佳答案

第一个只能从实现的类内部可见和访问。它被称为实例变量。

而该属性对其他类也是可见的。属性也由 iVar 支持。 @synthesize 正在幕后执行此操作。在您的情况下,可以使用属性名称访问支持 iVar(例如 simpleViewController)。但是应该通过 self(例如 self.simpleViewController)访问属性以简化内存管理并将其与普通 iVar 区分开来。 @synthesize 会为 iVar 生成 getter 和 setter,并根据属性声明(此处为 retain)进行内存管理。

现在你甚至不需要 @synthesize 了。只需声明一个属性。编译器将创建带有前缀下划线的支持 iVar 的属性。因此,可以通过 self.simpleTableViewController 或通过 _simpleTableViewController 访问它。

关于ios - 以下状态有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17358529/

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