[英]What's the difference between the following state?
也许这是一个幼稚的问题,但我真的很想知道细节。 我刚刚看过这段代码:
@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
在后台进行此操作。 在您的情况下,可以使用属性名称(例如simpleViewController
)访问支持iVar。 但是,应该通过self(例如self.simpleViewController
)访问属性,以简化内存管理并将其与普通iVar区分开。 @synthesize
将为iVar生成getter和setter,并根据属性声明(在此保留)进行内存管理。
如今,您甚至不再需要@synthesize
。 只需声明一个属性。 编译器将使用带有下划线前缀的支持iVar创建该属性。 因此,可以通过self.simpleTableViewController
或_simpleTableViewController
访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.