下划线在Objective-C中的成员变量名称中表示什么? [英] What does an underscore signify in the name of a member variable in Objective-C?
问题描述
可能重复:
在Objective C中使用下划线前缀属性名称
我是一名C / C ++开发人员,正在学习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 self;
}
@end
任何人都可以向我解释一下声明的含义
Can anyone please explain me the meaning of the statement
@synthesize coordinate=_coordinate;
我知道 @synthesize
的含义。但无法理解完整的陈述。
_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.
这篇关于下划线在Objective-C中的成员变量名称中表示什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!