Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top