Let’s say I have this interface:
// .h @interface DataObject : NSObject { NSString* value; } @property (retain) NSString* value; @end // .m @implementation DataObject @synthetize value @end
As far as I understand, the following two snippets are identical:
DataObject *o = [[[DataObject alloc] init] autorelease]; [o setValue: @'Hello']; DataObject *o = [[[DataObject alloc] init] autorelease]; o.value = @'Hello';
Am I correct? If yes, should I prefer one over another one? Or is it just a style preference?
Thank you.
It is a matter of style.
Dot syntax works in many places throughout Objective C, although it is only considered ‘acceptable’ for getters and setters.