关于使用@property @synthesize的语法

来源:互联网 发布:七匣子充值淘宝网 编辑:程序博客网 时间:2024/05/18 01:22


#import<Foundation/Foundation.h>

#import"Ppoint.h"


@interface Shape : NSObject {

@protected

floatwidth;

floatheight;

}

@property(nonatomic)float width,height;


- (id) initWithWidth : (float) _width Height : (float) _height ;


-(float) area;

-(void) draw;


@end

--------------------------------------------

#import"Shape.h"


@implementation Shape


@synthesize width,height;


- (id) initWithWidth : (float) _width Height : (float) _height

{

if(self = [superinit])

{

width = _width;

height = _height;

}

returnself;

}


-(float) area

{

returnwidth * height;

}


-(void) draw

{

NSLog(@"这是父类的绘图方法");

}


@end//Shape.h


主要是代码中加粗和加下划线的部分,他取代了平时写的setXxx和getXxx的用法

至于@property(参数)中参数到底写什么:请参考:http://blog.rapeflower.com/property-synthesize.html