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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With