Property declaration in Objective-C

Viewed 13815

Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?

So i have found out that you have to use underscore when synthesizing properties and that doesn't make a single bit of sense to me.

So, let's start. In our .h file we write this line:

@property (nonatomic) double speed;

In our .m file we do this:

@synthesize speed = _speed;

Why? As far as I know, property makes an instance variable and creates setters and getters for it. But what the hell does line

@synthesize speed = _speed 

do? As common sense tells me, we assign value in _speed to speed. Okay. Where did we declare _speed? Why doesn't compiler give us an error? What is it supposed to mean? Why such an obfuscated code?

My questions here:

What happens if I do just

@synthesize speed;

without _speed, will I get error or some bugs? What is the reason after this syntax? What were they thinking when making it? Where does _speed come from? What is it? Is it a pointer or a real value? What is going on?

7 Answers
Related