OC-@property和@synthesize关键字
来源:互联网 发布:linux proc net dev 编辑:程序博客网 时间:2024/06/10 05:57
@property是编译器的指令
什么是编译器的指令,编译器指令是用来告诉编译器要做什么
@property告诉编译器声明属性的访问器(getter/setter)方法
好处:免去我们手工写get和set方法。
2、用法:@property 类型名 方法名(去掉set)
如 @property int age;
相当于进行了进行了age的 set 和 get 方法的声明
-(void)setAge:(int)age;
-(void)age;
3、作用:
1、在xcode4.4 之前,用于帮我们实现get/set方法的声明
2、在xcode4.4 之后,有增强功能
4、注意事项
在老式的代码中
@property只能写在@interface @end 中
@property用来自动 生成成员变量的 get/set方法声明(xcode.4.4以前)
告诉property要生成的 get/set 方法声明的成员变量类型是什么
告诉property要生成的 get/set方法是哪个属性的,属性名称去掉下划线
1、@synthesize介绍
@synthesize是在 .m 文件中定义 set和get 方法的实现
2、用法:
@property int age; 写在 .h 文件 @interface @end中
@synthesize age ; 写在 .m 文件 ,@implementation @end 中 表示实现 age 的 get 方法
注意 要想在 . m 文件这样写[url=][url=][/url][/url][url=][url=]@synthesize[/url][/url] age;
必须 先在 .h 文件中使用 @ property int age;
@property和@synthesize 搭配使用,用于简化 set 和 get 方法的定义和实现
3、指定操作实例变量的@synthesize
[url=]@synthesize[/url] 方法名 = 实例变量名
当指定实例变量名以后,此时再不会操作默认的实例变量了
@synthesize age = _age,weight=_weight;
@synthesize name = _name;
本帖主要是写 xcode 4.4 以前@property 和@synthesize关键字
xcode 4.4以后 请看 @property增强使用
- OC @property 和 @synthesize 关键字
- OC-@property和@synthesize关键字
- OC关键字@Category@property@synthesize
- 关键字@property和@synthesize
- 关键字@synthesize 和@property
- OC学习小结之@property和@synthesize 关键字
- 黑马程序员--OC基础--@property和@synthesize关键字介绍
- @property关键字和@synthesize关键字
- OC-@property和@synthesize理解
- OC-@property和@synthesize理解
- OC之@property和@synthesize
- 【OC语言】第五篇·@property和@synthesize关键字、动态类型检测和构造方法
- oc中关于property和synthesize
- OC学习之@property和@synthesize用法
- OC学习那些事:@property和@synthesize
- oc点语法和@property @synthesize
- OC语言@property @synthesize和id
- OC中的@property、@synthesize和id
- hdu 4135 Co-prime 容斥原理
- UNIX环境高级编程之第8章:进程控制
- URAL 1774 Barber of the Army of Mages 网络流
- Jsp语法、指令及动作元素
- 大牛isap模板
- OC-@property和@synthesize关键字
- 【php】自动加载类autoload psr-0与psr-4标准
- hdu 4059 The Boss on Mars 容斥原理 数列通项公式
- Oracle OCP笔记(28)RMAN备份 - Catalog
- 认识GIT
- 1 时间序列基本概念
- 四大天王之内容提供者ContentProvider
- hdu 3388 Coprime 容斥原理 二分查找
- UVa 1623:Enter the Dragon(贪心)