Object-C 属性

来源:互联网 发布:php const 编辑:程序博客网 时间:2024/06/16 00:16

属性

微笑新建Student.h和.m文件

在Student.h文件中写属性的声明:

//属性的声明

@propertyNSString *companyAddress ;

//相当于声明了设置器和访问器

//-(void)setCompanyAddress:(NSString *)companyAddress;

//-(NSString *)companyAddress;


微笑//访问读写,原子性,内存管理

/*

 retain

 copy

 assign

 

 strong

 weak

 */ 

    strong 相当于 retaincopy,对像要用retain,copy,strong来描述

    weak 相当于 assign ,基本数据类型要用assingweak来描述;

 

@property (readwrite,nonatomic,retain)NSString *name ;

@property (nonatomic,assign)NSInteger age ;


微笑在.m文件中:

//相当于设置器和访问器的实现

//属性的实现

@synthesize companyAddress =_companyAddress ;


//属性的实现在.m文件中也可以不需要写



0 0
原创粉丝点击