ios 视频学习 3.4 @property属性和点语法
来源:互联网 发布:mac地址绑定错误 编辑:程序博客网 时间:2024/05/29 07:44
在一个类中声明另一个类的对象指针,要在该类的init方法中进行初始化。
#import "House.h"
@interface Person:NSObject
{
House * house;
int age;
}
-(void)getAge;
@end
//Person.m
@implementation Person
-(id)init()
{
if(self=[super init])
{
house=[ [ House alloc ] init ];
}
return self;
}
-(void)getAge
{
age=30;
return age;
}
@end
//新建一个House类
@interface House:NSObject
{
int area;
}
-(void)getArea;
@end
//Person.m
@implementation House
-(void)getArea
{
area=30;
return area;
}
@end
其中,init方法已经在父类中声明。打印类名的方法:
NSLog("self类名称:%@",[self class]);//当前类名
NSLog("父类名称:%@",[self superclass]);//当前类名
下面介绍@property和@synthesize声明。
先声明int numer;
@property (nonatomic,readonly) int numer;
@synthesize number;
nonatomic意思是非原子的(这个线程没有把number上锁,其他线程可以访问它),atomic意思是原子的(这个线程把number锁定)。
readonly代表只读,生成number方法,不生成setNumber:(int) 方法
用property声明number以后,在方法里面使用,需要用self.number使用。(直接用number应该也可以)
疑问:assign retain的意义。
- ios 视频学习 3.4 @property属性和点语法
- iOS点语法@property属性
- objective-c语法学习:@property属性和点语法
- 【无限互联】iOS开发视频教程 — 3.4 @property属性和点语法
- 属性,Property,点语法
- OC学习之@property和点语法
- @property 和 点语法
- OC基础之-Property(属性)和点语法
- 黑马程序员之ios学习总结——09 OC语言的点语法、@property和@synthesize
- iOS开发学习第二十一课——属性 / 点语法
- iOS成员变量、成员属性和点语法
- oc点语法和@property @synthesize
- @property、@synthesize关键字和点语法
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- ios的@property属性和@synthesize属性
- error 2005解决办法
- 为什么选择git
- HDU 3395 Special Fish | 费用流
- poj3437
- TestComplete总结三
- ios 视频学习 3.4 @property属性和点语法
- gradle打包android工程
- 调整hadoop 集群datanode 物理内容大小
- Mingw下python C api编译
- 浏览器工作原理
- A - Following Orders(11.3.1))
- 一个fork问题的思考
- php学习要点
- mac系统如何显示和隐藏文件 和 删除SVN隐藏文件