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;

}

posted on 2015-03-20 11:02  独叹梅花瘦2015  阅读(120)  评论(0编辑  收藏  举报

导航