简体   繁体   中英

What is this @synthesize statment doing?

Given the following class def:

@interface MyController : OtherController {
    NSString *_ID;
}
@property(nonatomic,retain) NSString *ID;
@end

and the following implementation:

@implementation DRMControllerNDS
@synthesize ID =_ID;
@end

What is the @synthesize statement doing here? Specifically why are we are setting the _ID instance variable value to the ID property? Isn't _ID going to be nil at this point in execution? I have seen this construct used many times and am yet to understand its purpose...

Can anyone explain this?

用简单的英语,@synthesize行说“为属性创建getter和setter方法”ID“,但是不要使用名为”ID“的实例变量(默认值)来存储值,使用名为”的实例变量“ _ID“相反。”

If you tried to access instanceOfMyController._ID , you'll get an error because the ._ID property doesn't exist; the @synthesize directive allows you to use the dot notation.

See this question for more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM