What is the difference between the following ways of defining variables?
@interface MyClass: NSObject
{
NSString *string;
}
@property (nonatomic, strong) NSString *string;
vs.
@interface MyClass: NSObject
@property (nonatomic, strong) NSString *string;
I know that @property takes care of setter and getter (in conjunction with @synthesize) and I know that both ways work fine.
I also know that the latter way does not work for NSArray, NSDictionary. But it works for IBOutlets linked to IB.
Does it have anything with alloc/init? or maybe there is a concept that I am missing totally?
Thanks.
The compiler will automatically create the
NSString *string;ivar for you. There is no difference under the latest SDK.I’ve never ran into issues with NSDictionary not being backed by an explicit ivar.
Update:
Here is the docs on declared properties.
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjectiveC/Chapters/ocProperties.html