I know that the @property generates the getters and setters in Objective-c. But I’ve seen some classes where they declare attributes with their respective @property and some times just the @property with no attributes and seams to work the same way. Whats the difference?
I know that the @property generates the getters and setters in Objective-c. But I’ve
Share
No you don’t.
@propertydeclares a property which is a getter and optionally a setter (for read/write properties). The generation of the getter and setter is done by the@synthesizein the implementation (or by you writing the getter and setter).Do you mean like this?
In the modern Objective-C run time, if you
@synthesizethe property, you can leave out the instance variable declaration and the compiler will put it in for you. Whether you explicitly declare the instance variable or not is a matter of personal preference.Just to confuse you a bit, in the very latest compiler, you can omit the
@synthesizeand the compiler will put it in for you as long as you haven’t explicitly created a getter or setter.