OC 中 @synthesize 关键字介绍和使用

@synthesize用法

1)@property int age; @synthesize age; 表示生成.h中变量 age的 get和 set方法

注意:
    如果@synthesize 变量名要先在.h文件中声明
    @property int age; @synthesize age;展开形式如下:

    .h
    -(void)setAge:(int ) age;
    -(int)age;

  .m
  -(void)setAge:(int) age{
    slef->age=age;
  }
  -(int)age{
    return age;
  }

   错误用法,只写了@synthesize,没有写 @property,也没有定义变量 NSString *name;

 

如果两个实例变量的类型一致

@synthesize age,weight;

  

原文地址:https://www.cnblogs.com/developer-wang/p/4500534.html