考慮下面的類DEF:@synthesize statment在做什麼?
@interface MyController : OtherController {
NSString *_ID;
}
@property(nonatomic,retain) NSString *ID;
@end
和下面的實現:
@implementation DRMControllerNDS
@synthesize ID =_ID;
@end
什麼是@synthesize
語句在這裏做什麼?具體爲什麼我們將_ID
實例變量值設置爲ID
屬性?在這一點上,_ID
不是nil
嗎?我已經看到這個構造使用了很多次,並且還沒有明白它的目的...
任何人都可以解釋這個嗎?
這是一個區分直接訪問變量(_var)和通過合成訪問器(self.var)訪問的約定。 – Jano
類似問題:[1](http://stackoverflow.com/questions/3802851/objective-c-synthesize-property-name-overriding),[2](http://stackoverflow.com/questions/3277209/can -someone-explain-this-synthesize-syntax),[3](http://stackoverflow.com/questions/6112283/question-about-synthesize/6112553),[4](http://stackoverflow.com/questions/3802851),[5](http://stackoverflow.com/questions/382051),[6](http://stackoverflow.com/questions/3266467),[7](http://stackoverflow.com/問題/ 5170631),[8](http://stackoverflow.com/questions/3277209),[9](http://stackoverflow.com/questions/719788) – Jano
@Sabobin:每個數字都是一個鏈接。 –