@synthesize是一個(gè)編譯器指令, 它可以簡化我們getter/setter方法的實(shí)現(xiàn)
什么是實(shí)現(xiàn):
在聲明后面寫上大括號(hào)就代表著實(shí)現(xiàn)
1.在@synthesize后面告訴編譯器, 需要實(shí)現(xiàn)哪個(gè)@property生成的聲明
- 告訴@synthesize, 需要將傳入的值賦值給誰和返回誰的值給調(diào)用者
//@synthesize age = _age;
- (void)setAge:(int)age
{
_age = age;
}
- (int)age
{
return _age;
}
@synthesize age = _number;
- (void)setAge:(int)age
{
_number = age;
}
- (int)age
{
return _number;
}
// 如果在@synthesize后面沒有告訴系統(tǒng)將傳入的值賦值給誰, 系統(tǒng)默認(rèn)會(huì)賦值給和@synthesize后面寫得名稱相同的成員變量
@synthesize age;