开发者

What does an underscore signify in the name of a member variable in Objective-C? [duplicate]

开发者 https://www.devze.com 2023-02-25 16:08 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Prefixing property names with an underscore in Objective C
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Prefixing property names with an underscore in Objective C

I am a C/C++ developer and am learning Objective-C. Recently I started on a tutorial that I found on net. The code is as below:

@interface MapDemoAnnotation : NSObject <MKAnnotation> {
    CLLocationCoordinate2D _coordinate;
}

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate;

@end

@implementation MapDemoAnnotation

@synthesize coordinate=_coordinate;

- (id)initWithCoordinate:(CLLocationCoordinate2D)coordinate {
    self = [super init];
    if (self != nil) {
        _coordinate = coordinate;
    }
    return sel开发者_JAVA技巧f;
}

@end

Can anyone please explain me the meaning of the statement

@synthesize coordinate=_coordinate;

I know the meaning of @synthesize. But could not understand the complete statement. _coordinate is a member variable. But what is coordinate? Where is it declared?


Basically, it doesn't mean anything to the compiler. It's just a coding practice used on private instance variables. Your code isn't going to break if you don't use it.

0

精彩评论

暂无评论...
验证码 换一张
取 消