Ios 什么';以下状态之间的区别是什么?
也许这是个有点幼稚的问题,但我真的很想知道细节。我刚刚看到了以下代码:Ios 什么';以下状态之间的区别是什么?,ios,objective-c,synthesize,Ios,Objective C,Synthesize,也许这是个有点幼稚的问题,但我真的很想知道细节。我刚刚看到了以下代码: @implementation SimpleMainViewController { SimpleTableViewController *simpleTableViewController; AboutViewController *aboutViewController; } 这个和下面的有什么区别 @interface SimpleMainViewController : UIViewControll
@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支持。
@synthesis
是在幕后进行的。在您的情况下,可以使用属性的名称(例如,simpleViewController
)访问支持iVar。但是应该通过self(例如self.simpleViewController
)访问属性,以简化内存管理,并将其与普通iVar区分开来。@synthesis
将生成iVar的getter和setter,并根据属性声明(此处为retain)进行内存管理
现在你甚至不再需要
@synthesis
。只需申报一项财产。编译器将使用带有前缀下划线的支持iVar创建属性。因此,可以通过self.simpleTableViewController
或\u simpleTableViewController
访问它。第一个只能从实现的类内部看到和访问。它被称为实例变量
而该属性对其他类也是可见的。房产也有iVar支持。@synthesis
是在幕后进行的。在您的情况下,可以使用属性的名称(例如,simpleViewController
)访问支持iVar。但是应该通过self(例如self.simpleViewController
)访问属性,以简化内存管理,并将其与普通iVar区分开来。@synthesis
将生成iVar的getter和setter,并根据属性声明(此处为retain)进行内存管理
现在你甚至不再需要
@synthesis
。只需申报一项财产。编译器将使用带有前缀下划线的支持iVar创建属性。因此,您可以通过self.simpleTableViewController
或\u simpleTableViewController
访问它,谢谢您的关注!他们没有任何其他的区别吗?他们是不同的!为答案添加了更多信息。@Pfitz-Thx了解详细信息!回答得很好,很简洁,很有帮助+感谢您的关注!他们没有任何其他的区别吗?他们是不同的!为答案添加了更多信息。@Pfitz-Thx了解详细信息!回答得很好,很简洁,很有帮助+1.