@property :可以自动生成成员变量的getter和setter声明。
e.g. :
@property int age ;(自动生成 _age变量)
@property NSString *name;
@synthesize 为成员变量方法的实现
e.g.:
@synthesize age = _age;
默认会访问_这个变量
@synthesize会自动生成@private类型的变量(成员变量里不用声明)
@property会全部生成(成员变量不用写,@synthesize也不用声明,变量为私有。)
注:如果@synthesize age;默认会访问age这个成员变量,而不是_age。
本文介绍了Objective-C中@property和@synthesize的使用方法,包括如何自动生成成员变量的getter和setter声明,以及@synthesize如何自动生成@private类型的变量。此外还解释了@synthesize与默认访问变量的区别。
725

被折叠的 条评论
为什么被折叠?



