Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?
I am new to iphone development.I am doing research on voice recording in iphone .I have downloaded the "speak here" sample program from Apple.It consist of LevelMeter.h file, in which
@interface LevelMeter : UIView {
CGFloat _level, _peakLevel;
}
The property are set as
@property CGFloat level;
@property CGFloat peakLevel;
What is the use of declaring a varible like _level and setting its property as level.Please explain me.Thanks.
The underscore represents stuff that should only be accessed from within its own class. Thus, the instance variable shouldn't be accessed from outside the class, but the property can be.
Reminder
The
@property
directive is equivalent to declaring both a setter and a getter. In the case oflevel
,can be replaced by
Your question
Why declare a property named
level
for a variable named_level
and why name a variable with a leading_
in the first place? I don't know.How it works, is answered in
LevelMeter.m
: