Obj-C @synthesize

时间:2011-06-11 18:02:21

标签: iphone objective-c xcode

  

可能重复:
  Prefixing property names with an underscore in Objective C

iPhone App Developer初学者:

in .h

@property (nonatomic, retain) IBOutlet UILabel *detailDescriptionLabel;

in .m

@synthesize detailDescriptionLabel = _detailDescriptionLabel;

我习惯看

@synthesize detailDescriptionLabel;

= _让我失望,这是做什么的?

2 个答案:

答案 0 :(得分:6)

每个属性都由实例变量支持。该语言允许以不同的方式命名它们。通过执行@synthesize detailDescriptionLabel = _detailDescriptionLabel;,您基本上会说使用_detailDescriptionLabel作为属性detailDescriptionLabel的支持实例变量。如果您只是@synthesize detailDescriptionLabel;,它会隐含地理解实例变量具有相同的名称。

答案 1 :(得分:0)

n .h

    UILabel *_detailDescriptionLabel;
}
    @property (strong, nonatomic) IBOutlet UILabel *detailDescriptionLabel;

in .m

@synthesize detailDescriptionLabel = _detailDescriptionLabel;

此行表示属性“detailDescriptionLabel”将具有名为“_detailDescriptionLabel”的类属性的setter和getter

如果名称相同,您将拥有

@synthesize detailDescriptionLabel;