可能重複:
Prefixing property names with an underscore in Objective C下劃線在Objective-C中的成員變量的名稱中表示什麼?
我是一個C/C++開發人員和我學習Objective-C。最近我開始在網上找到一個教程。代碼如下:
@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 self;
}
@end
誰能請解釋一下我的發言
@synthesize coordinate=_coordinate;
我知道@synthesize
的意思意思。但無法理解完整的陳述。 _coordinate
是一個成員變量。但是什麼是coordinate
?它在哪裏宣佈?
'_'被稱爲下劃線,這個問題在此之前已經提過很多次了。重複:[1](http://stackoverflow.com/questions/5582448/underscore-prefix-on-property-name)[2](http://stackoverflow.com/questions/3521254/prefixing-property-names- with-an-underscore-in-objective-c)[3](http://stackoverflow.com/questions/2371489/why-do-you-use-an-underscore-for-an-instance-variable-but-不是相應的)[4](http://stackoverflow.com/questions/822487/how-does-an-underscore-in-front-of-a-variable-in-a-cocoa-objective-c-班級工作)[5](http://goo.gl/8hqNu) – 2011-04-14 06:04:39