-1

What is the difference between these two lines of code? They both work and both do the same, but is there any reason why one is preferable to the other, and if so why?

[textLabel setAlpha:0];
textLabel.alpha=0;
jscs
  • 63,694
  • 13
  • 151
  • 195
RGriffiths
  • 5,722
  • 18
  • 72
  • 120

3 Answers3

1

Old style and new style, both do the same. No difference and no preference.

Volker
  • 4,640
  • 1
  • 23
  • 31
1

Using the ".alpha" property calls the setter, which is "setAlpha:", so ultimately you're calling the exact same code.

It's just a style difference and/or a preference for you.

Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

There is no difference. The compiler translates

textLabel.alpha = 0;

into

[textLabel setAlpha:0];

However, some people prefer to use the "dot notation" only with properties, even if the language does not impose this restriction.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382