Object-C 属性
2015-07-26 10:32
381 查看
属性
新建Student.h和.m文件
在Student.h文件中写属性的声明:
//属性的声明
@property
NSString *companyAddress ;
//相当于声明了设置器和访问器
//-(void)setCompanyAddress:(NSString *)companyAddress;
//-(NSString *)companyAddress;
//访问读写,原子性,内存管理
/*
retain
copy
assign
strong
weak
*/
strong 相当于 retain或copy
,对像要用retain,copy,strong来描述
weak 相当于 assign ,基本数据类型要用assing或weak来描述;
@property (readwrite,nonatomic,retain)
NSString *name ;
@property (nonatomic,assign)
NSInteger age ;
在.m文件中:
//相当于设置器和访问器的实现
//属性的实现
@synthesize companyAddress =
_companyAddress ;
//属性的实现在.m文件中也可以不需要写
新建Student.h和.m文件
在Student.h文件中写属性的声明:
//属性的声明
@property
NSString *companyAddress ;
//相当于声明了设置器和访问器
//-(void)setCompanyAddress:(NSString *)companyAddress;
//-(NSString *)companyAddress;
//访问读写,原子性,内存管理
/*
retain
copy
assign
strong
weak
*/
strong 相当于 retain或copy
,对像要用retain,copy,strong来描述
weak 相当于 assign ,基本数据类型要用assing或weak来描述;
@property (readwrite,nonatomic,retain)
NSString *name ;
@property (nonatomic,assign)
NSInteger age ;
在.m文件中:
//相当于设置器和访问器的实现
//属性的实现
@synthesize companyAddress =
_companyAddress ;
//属性的实现在.m文件中也可以不需要写
相关文章推荐
- Object-c 设置器与访问器
- OC学习笔记之protocol
- 对象的持久化存储
- Swift语言与Objective-C语言混合编程
- ObjectInputStream and ObjectOutputStream
- setObject设置boolean的类型为啥不行?
- Objective-C中的@property和@synthesize用法
- Objective-C 类目
- object c中 new和alloc区别
- 关于Objective-C格式化处理相关规范
- Objective-C面向对象-对象和类
- javascript笔记07:使用Object类为实例定义方法和属性
- Object-C 内存管理模式初探(一)
- Fit_primitives_object_model_3d.hdev相关例程学习
- Objective-C设计模式——桥接Bridge(接口适配)
- 挖一挖C#中那些我们不常用的东西之系列(4)——GetHashCode,ExpandoObject
- javascript Object的长度
- Objective-C学习笔记(二十七)——方法的重载与重写
- Objective C Bridging header —— swift MD5
- Objective-C学习笔记(二十六)——成员变量的继承学习