可能重複:
How does an underscore in front of a variable in a cocoa objective-c class work?
Difference between self.ivar and ivar?
Synthesized property and variable with underscore prefix: what does this mean?時使用self.propertyname和_propertyname
要在對象C使用屬性,我有兩個選擇,其中一個應我用?
choice1:self.property = xxxx;
選擇2:_property = XXX
例如:
//.h file
@interface ViewController : UIViewController
@property (retain, nonatomic) NSArray *myArray;
@end
//.m file
@interfaceViewController()
@end
@implementation ViewController
- (void)doing {
_myArray = [[NSArray alloc] init]; //choice one
self.myArray = [[NSArray alloc] init]; //choice two
}
@end
@CodaFi請按照複製鏈:) –
@傑克,這是他的工作。 :P – CodaFi
問題不在於下劃線語法。他問的是設置變量的兩種方法之間的區別,這不是語法或慣例的問題。 –