Possible Duplicate:
Properties declared as instance variables too?
Let’s say I have an objective c class interface like:
@interface {
NSString * someString;
}
@property (nonatomic, retain) NSString * someString;
with an @implementation that @synthesizes the string and does some other stuff.
What I’d like to know is, whether it’s necessary to have that NSString * someString object pointer declaration within the brackets at all. (As an aside, is there a specific term for the space between the brackets where variables are defined?) It seems like the code will work fine if I omit the NSString * someString declaration, and the @property line has all the same information about type. So, if it’s not necessary to have the variable declaration, why does the option exist at all? What happens if you have conflicting types in the variable declaration and the @property declaration?
For the most part, it shouldn’t be necessary, since
@synthesizewill create a variable if it is not predefined. Also, you can create your own variable with@synthesizeas well, using:That will create a getter method (
aVar), a setter method (setAVar), and an instance variable named_theVariableNamewhich you can use for memory management purposes.However, I don’t know if
@dynamicwill do the same, and if implementing your own setters and getters, I think you need the declaration…