黑马程序员技术交流社区

标题: 【oc】@synthesize 指令 [打印本页]

作者: 你说呢    时间: 2015-7-27 08:48
标题: 【oc】@synthesize 指令
@synthesize
        是在.m 文件中定义set和get方法的实现
@synthesize int age;表示生成.h中变量age的set方法和get方法
注意:@synthesize 变量名要先在.h 文件中声明
@synthesize  age;展开如下:生成的是agel;
-(void)setAge: (int )age{
        Self->age=age;
}
-(int )age{
Return  self->age;
}
如果两个实例变量类型一致:;
@property int  age;
.h    @property int weight;   .m -------@synthesize age,weight;
@property int weight,age;   .m -------@synthesize age,weight;
指定操作实例变量的@synthesize
@synthesize 方法名    实例变量名
当指定实例变量名以后,此时再不会生成操作默认的实例变量了
@synthesize  age=_age,weight=_weight; 展开
-(void)setAge: (int )age{
        _age=age;
}





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2