1

I've been trying to improve my "Objective-C" programming style, and I came across this article which talks about variables and setting values. It helped me clear up a lot of things, but I still have a question.

Jonathan Sterling mentions in his answer both

self.qux = blah;

and

[self setQux:blah];

Is there any difference between the two? If so, which one is the preferred coding style?
And I believe the correct term for the second example is getter and setter methods, but what is the first style called?

Community
  • 1
  • 1
oelna
  • 2,210
  • 3
  • 22
  • 40
  • 2
    http://stackoverflow.com/questions/1249392/dot-notation-vs-message-notation-for-declared-properties? – Tomas Camin May 14 '14 at 10:58
  • Thank you, a great read! I did not know what the different styles were called, so I had a hard time finding something on SO about the subject. This helped. – oelna May 14 '14 at 11:03

1 Answers1

0

They are both the same. You can use either of the style of the code. It is called as property. A property has both getter and setter.

For me,

For property, I will use self.myProperty.

When it is a method, I will use [self myMethod];

It is really depends on your programming style.

Ricky
  • 10,485
  • 6
  • 36
  • 49
  • 2
    Message passing can be helpful if you have several read-only properties and forget which ones are and aren't. In that case `[self setMyVariable:];` wouldn't appear in Xcode's drop-down list. But of course you'd be shown an error if you use dot notation anyway, so like you've said, it depends on your programming style. – sooper May 14 '14 at 11:14