Possible Duplicate:
How does an underscore in front of a variable in a cocoa objective-c class work?
I see often nowadays declarations like this:
@property SomeClass* foo;
@synthesize foo=_foo;
Most of the examples use ARC as well, but I am not sure it is connected to this.
I have the feeling that I am missing something obvious, but cant put my finger on it.
Any idea?
It is not connected to ARC. The @property keyword is a feature used to indicate to the compiler (and to the class user) that there will be getter and setter methods for that “property.” In this case, there is an expectation that there will be a getter method called “foo” and a setter method called “setFoo”. The @synthesize keyword tells the compiler to synthesize a generic getter and setter method as opposed to you providing your own. @synthesize foo=_foo is telling the compiler to synthesize these generic methods with a backing instance variable called “_foo”. This _propertyName notation is a stylistic choice that many objective c developers use. The basic result is that you get this code:
There maybe some additional features that the compiler provides in the synthesized getter and setter, but that is the gist of it.