#import <Fountion/Fountion.h>
@interface Person :NSobject //.h 文件裏
{
int _age;
int _heigh;
} // 成員變量
@property age; // 編譯器自動生成 - (void)setAge:(int)age;
// - (void)age:
@property heigh; //同樣編譯器自動生成聲明,設置方法與獲取方法。
@end
#import <Fountion/Fountion.h>
#import "Person" // .m 文件
@implementation Person
@synthesize age = _age; // 編譯器自動生成實現 , -(void)setAge:(int)age
// { _age = age;
// }
// -(int)age
// { return _age;
// }
如何類型一樣可以一塊寫例如:
`
@property int age,weight;
如果成員變量不存在會自動生成。並且生成的是private(私有的只能當前類的對象方法訪問)並且類型是根據property 聲明中的類型。
如果實現時聲明爲property age;不是age = _age;就會直接訪問跟 age一樣對象的成員變量。如果age不存在會生成age.
注意:如果 方法的實現部分,已經寫出來那麼優先調用自己寫出來的,不會調用自動生成的。