- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- int _age;
- int _height;
- double _weight;
- NSString *_name;
- }
- // @property:可以自动生成某个成员变量的setter和getter声明
- @property int age;
- @property int height;
- @property double weight;
- @property NSString *name;
- @end
复制代码 上面的四条@property语句的功能就相当于一下代码:
- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- int _age;
- int _height;
- double _weight;
- NSString *_name;
- }
- - (void)setAge:(int)age;
- - (int)age;
- - (void)setHeight:(int)height;
- - (int)height;
- - (void)setWeight:(double)weight;
复制代码
|
|