您的位置:首页 > 运维架构

关于使用@property @synthesize的语法

2012-12-25 10:39 330 查看
#import
<Foundation/Foundation.h>
#import
"Ppoint.h"

@interface Shape : NSObject {
@protected
float
width;
float
height;
}
@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 = [super
init])
{
width = _width;
height = _height;
}
return
self;
}

-(float) area
{
return
width * height;
}

-(void) draw
{
NSLog(@"这是父类的绘图方法");
}

@end//Shape.h

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

至于@property(参数)中参数到底写什么:请参考:http://blog.rapeflower.com/property-synthesize.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  property synthesize
相关文章推荐