I read some tutorials here about properties ,but i still have some doubts to clarify, is there a difference between
@interface MyClass : NSObject {
}
@property(nonatomic,retain) NSString *temp;
@end
AND
@interface MyClass : NSObject {
NSString *temp;
}
@property(nonatomic,retain) NSString *temp;
@end
The difference is that in the first version, the compiler will automatically create an instance variable (IIRC, it will be named
_tempbut I don’t know for sure). This is only supported on iOS and Mac 64 bit.In the second example, you provide the variable.
There’s actually a way to tell the compiler which variable to use for the property, which I use a lot:
This way the variable and the property have different names and you can’t confuse them (e.g. by forgetting to prefix
self.).Minor side-note: it’s often desirable to use
copyinstead ofretainforNSString *, since you might assign anNSMutableString *to the property. Now if you would change that mutable string unexpected things might happen.