Obj-C @synthesize

Possible duplicate:
An underscore property name prefix in Objective-C

IPhone app developer here:

in .h

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

in .m

 @synthesize detailDescriptionLabel = _detailDescriptionLabel; 

I'm used to seeing

 @synthesize detailDescriptionLabel; 

= _ casts me away, what does it do?

+4
source share
2 answers

Each property is supported by an instance variable. Language allows you to name them differently. By doing @synthesize detailDescriptionLabel = _detailDescriptionLabel; , you basically say that use _detailDescriptionLabel as the database instance variable for the detailDescriptionLabel property. If you just do @synthesize detailDescriptionLabel; , he implicitly understands that the instance variable has the same name.

+6
source

nh

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

in .m

 @synthesize detailDescriptionLabel = _detailDescriptionLabel; 

This line means that the "detailDescriptionLabel" property will have a setter and getter for the class attribute named "_detailDescriptionLabel"

If the name was the same, you will have

 @synthesize detailDescriptionLabel; 
0
source

All Articles