@property @synthesize如何使用

@property是让编译器自动产生函数申明

  不再写下面2行代码

  -(void) setAge:(int)newAge;

  -(void) age;

  只需要下列一行就可以代替

  @property int age;

 

@synthesize 意思是合成

  @synthesize就是编译器自动实现getter和setter函数

  不用写下列代码

  - (void) setAge:(int)newAge

  {

    age=newAge;

  }

  -(int) age

  {

    return age;

  }

  只需要些

  @synthesize age;

posted @ 2014-12-08 19:34  Rui.peng  阅读(174)  评论(0编辑  收藏  举报