use of @property and @synthesise?

declaration, ios, objective-c, properties

Solution

`@property` and `@synthesize` are two objective C keyword that allow you to easily create your properties and therefore avoid to write by hand getters and setters methods of the property.

The `@property` define the property itself, should be placed in the header file and can get some attributes (as for example : strong, nonatomic, retain assign, copy), the `@synthesize` should be placed into the implementation file and tell the compiler to generate the body of getter and setter method.

These two keyword are extremely useful when coupled with the right use of their attributes, because they take care of the generation of the property code and most of all they take care of the memory management of the property.

Problem

I was wondering what the point of @property and @synthesise were. At the moment I use the following to declare something: ``` //Class.m #import "Class.h" CCNode *node; @implementation //init, etc.. ``` But I have seen others use: ``` @property (nonatomic, etc..) CCNode* node; @synthesise (nonatomic, etc..) node; //I am not too sure on how this type of declaration works, please correct me on how it's done. ``` They both seem to work in the same way, what are the advantages of the @property and @synthesise way? Do they do different things, if so, what?

Original source