- #import <Foundation/Foundation.h>
- @interface Person : NSObject
- {
- int _age;
- float _height;
- }
- @property(nonatomic ,assign)int age;
- @property(nonatomic ,assign)float height;
- - (void)test;
- @end
- #import "Person.h"
- @implementation Person
- // @property int age是编译器特性,只是帮程序员生成一些代码,默认生成成员变量_age和setter,getter方法;
- // @synthesize age = age 表示可以用age代替age属性生成的_age成员变量。
- @synthesize age = age;
- - (void)test
- {
- NSLog(@"%d--%d",_age,age);
- }
- @end
复制代码 |