关于使用@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
<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
相关文章推荐
- OC_关于property、synthesize的使用
- OC语言——点语法和成员变量的4种作用域及property和synthesize的使用
- OC @property ,@synthesize和点语法的使用
- OC中点语法、property跟synthesize用法
- 关于系统中使用多个PropertyPlaceholderConfigurer的配置及PropertyOverrideConfigurer
- OC核心语法(1)点语法、变量作用域、@property@synthesize和id
- 关于Apache mod_rewrite的中文配置、使用和语法介绍(实现URL重写和防盗链功能)
- 关于系统中使用多个PropertyPlaceholderConfigurer的配置
- 关于 Spring 中使用 context:property-placeholder 属性占位符设置配置文件
- 装饰器语法糖(@staticmethod/@classmethod/@property)原理剖析及使用场景说明
- Objective-C语言-点语法和变量作用域-@property @synthesize和id
- 关于Apache mod_rewrite的中文配置、使用和语法介绍(实现URL重写和防盗链功能)
- 关于系统中使用多个PropertyPlaceholderConfigurer的配置(不错)
- 使用外部属性文件(关于PropertyPlaceholderConfigurer)
- 关于一个MYSQL语法(在查询中使用count)的兼容性问题
- OC的特有语法-分类Category、 类的本质、description方法、SEL、NSLog输出增强、点语法、变量作用域、@property @synthesize关键字、Id、OC语言构造方法
- python的property语法的使用
- 关于使用<s:property value="">形式取得 数据库图片地址的注意事项
- 黑马程序员——Objective-C学习之@property @synthesize和id及点语法
- python的property语法的使用