Reputation: 46719
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.
Upvotes: 0
Views: 1196
Reputation: 82535
In August 2009, there was a brouhaha in the blogosphere regarding use of dot syntax.
Upvotes: 0
Reputation: 17404
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.
Upvotes: 4
Reputation: 88355
I think the dot notation is preferable over calling the set method. I think the code is more readable, and the dot notation more clearly identifies that you're setting a property, as opposed to just calling a method on the class.
Upvotes: 1