Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it wrong to use the dot syntax as a getter?

I know that the . is a shortcut for a setter. Sometimes, I use that kind of code:

cell.textLabel.text = [NSString stringWithFormat:@"this is row %i", indexPath.row];

This works as expected, but I was wondering, is it better (or more correct maybe?) to write

cell.textLabel.text = [NSString stringWithFormat:@"this is row %i", [indexPath row]];

Or, in other words, should I use the dot syntax only with the = operator, like

aTextField.text = @"whatever";

Any links/docs are welcome, thanks :)

PS. In case you didn't see the tag, I'm talking about iOS here.

like image 441
phi Avatar asked Jan 20 '11 10:01

phi


1 Answers

Dot (.) is not only a shortcut for setter, it's shortcut for getter too. You can use dot for getter too. There is no problem, neither this is bad practice. From Obj-C 2.0 programming guide, "You can use the dot syntax to invoke accessor methods using the same pattern as accessing structure elements. The dot syntax is purely “syntactic sugar”". Note that, it is saying about accessor method, not only setter.

like image 57
taskinoor Avatar answered Sep 30 '22 03:09

taskinoor