Objective-C 中@property 与@ synthesize

@property 在头文件中使用 可以让编译好器自动编写一个与数据成员同名的方法声明来省去读写方法。

test.h

@property int age;

-(int)age;

-(void)setAge:(int)myAge;

test.m

@synthesize age;   等效于在.m文件中实现2个方法

-(int)age

{

  return age;

}

-(void)setAge:(int)myAge

{

  age =myAge;

}

原文地址:https://www.cnblogs.com/520myp1314/p/4353114.html