例如:
@property (nonatomic, assign) int height;
Xcode自动生成
对应的set方法:- (void)setHeight:(int)height;
get方法:- (int)height;
注释:
其中p.height = 100; //实质是调用set方法
NSLog(@"height is", p.height); //实质是调用get方法
#import "ViewController.h"
@interface ViewController ()
{
NSInteger aAge;
}
@property (nonatomic,assign) NSInteger age;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.age = 18;
NSInteger myAge = self.age;
}
-(void)setAge:(NSInteger)age{
NSLog(@"++++++++++++++");
aAge = age;
}
-(NSInteger)age{
NSLog(@"---------------");
return aAge;
}