OBJ-C @property和@synthesize关键字学习笔记
来源:互联网 发布:java重写的作用 编辑:程序博客网 时间:2024/06/05 05:33
============================================================
@property和@synthesize关键字
===========================================================
@property
格式: @property int age;相当于声明了实例变量的set和get方法;
放在@interface @end 之间;
@synthesize
格式: @synthesize age;相当于实现了实例变量的set和get方法;
放在@implementation @end之间;
---------------------------------------------
@synthesize age 写完后,系统会自动帮我们生成一个实例变量age
@synthesize age的展开:(重点!!!!!)
-(void)setAge:(int)age{
self->age = age;
}
-(int)age{
return age;
}
------------------------------------------------------
【掌握】@synthesize指定实例变量赋值
例如: @synthesize age = _b;
就相当于: -(void)setAge:(int)age
{
_b = age;
}
-(int)age
{
return _b;
}
意思就是它不会创建一个age的实例变量了,而是一个_b的实例变量;
-------------------------------------------------------------
@property int age,weight,height;
@property NSString *name;
(@property可以这样连续声明,但是不同类型的要区分开)
@synthesize age,weight,height,name;
(@synthesize可以这样连续实现,即使类型不同也可以放到一块,但最好 做下区分)
==========================================================
@property增强用法
1.xcode4.4之后,可以只使用@property 而不适用@synthesize
2.声明和实现了_age等实例变量的set和get方法
3.操作的是带有下划线的实例变量;
4.如果我们当前类,没有下划线的实例变量,则系统会帮我们自动生成;
5.生成的下划线变量是私有的,不允许被子类继承
===========================================================
@property增强下重写set和get方法
在.m中只能重写一个,不能同时手动实现!!!重写一般是为了加上限定条件。
如果都要重写的话,一定要加上@synthesize 的实现。
@property和@synthesize关键字
===========================================================
@property
格式: @property int age;相当于声明了实例变量的set和get方法;
放在@interface @end 之间;
@synthesize
格式: @synthesize age;相当于实现了实例变量的set和get方法;
放在@implementation @end之间;
---------------------------------------------
@synthesize age 写完后,系统会自动帮我们生成一个实例变量age
@synthesize age的展开:(重点!!!!!)
-(void)setAge:(int)age{
self->age = age;
}
-(int)age{
return age;
}
------------------------------------------------------
【掌握】@synthesize指定实例变量赋值
例如: @synthesize age = _b;
就相当于: -(void)setAge:(int)age
{
_b = age;
}
-(int)age
{
return _b;
}
意思就是它不会创建一个age的实例变量了,而是一个_b的实例变量;
-------------------------------------------------------------
@property int age,weight,height;
@property NSString *name;
(@property可以这样连续声明,但是不同类型的要区分开)
@synthesize age,weight,height,name;
(@synthesize可以这样连续实现,即使类型不同也可以放到一块,但最好 做下区分)
==========================================================
@property增强用法
1.xcode4.4之后,可以只使用@property 而不适用@synthesize
2.声明和实现了_age等实例变量的set和get方法
3.操作的是带有下划线的实例变量;
4.如果我们当前类,没有下划线的实例变量,则系统会帮我们自动生成;
5.生成的下划线变量是私有的,不允许被子类继承
===========================================================
@property增强下重写set和get方法
在.m中只能重写一个,不能同时手动实现!!!重写一般是为了加上限定条件。
如果都要重写的话,一定要加上@synthesize 的实现。
0 0
- OBJ-C @property和@synthesize关键字学习笔记
- iOS学习笔记16—@synthesize obj=_obj的意义详解 @property和@synthesize
- iOS学习笔记16—@synthesize obj=_obj的意义详解 @property和@synthesize
- 【Objective-C学习笔记】核心语法——实例变量作用域、关键字@property和@synthesize
- 黑马程序员----Objective-C学习笔记之@property关键字和@synthesize用法
- Objective-C 【@property和@synthesize关键字】
- 关键字@property和@synthesize
- 关键字@synthesize 和@property
- @property关键字和@synthesize关键字
- 【Objective-C学习-3】@property和@synthesize
- OC @property 和 @synthesize 关键字
- OC-@property和@synthesize关键字
- @synthesize obj=_obj的意义详解 @property和@synthesize
- @synthesize obj=_obj的意义详解 @property和@synthesize
- @synthesize obj=_obj的意义详解 @property和@synthesize
- @synthesize obj=_obj的意义详解 @property和@synthesize
- @synthesize obj=_obj的意义详解 @property和@synthesize
- @synthesize obj=_obj的意义详解 @property和@synthesize
- 51Nod-1134-最长递增子序列
- 用Base64加解密时发现的问题(其实时java基础问题byte[]转String)
- mongo 分片Replica Sets+Sharding架构
- OBJ-C类的继承和派生学习笔记
- OBJ-C组合模式学习笔记
- OBJ-C @property和@synthesize关键字学习笔记
- OBJ-C实例变量修饰符;私有变量;私有方法;description;多态;点语法学习笔记
- mongodb副本集的配置及node.js的使用
- Mongodb事务模拟
- shader回顾02 --- 固定管线编程基础
- 为什么Java中1000==1000为false而100==100为true?
- 项目记录38--tolua 股市网络爬虫软件解析json,html
- 易經大意 421_440
- 使用wpa_supplicant中犯的小错误