Is it wrong to use point syntax as a getter?

I know that. is a shortcut to the setter. Sometimes I use this code:

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

This works as expected, but I was wondering if it’s better (or rather, perhaps?) To write

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

Or, in other words, you should use the point syntax only with the = operator, for example

aTextField.text = @"whatever";

Any links / documents are welcome, thanks :)

PS. If you do not see the tag, I'm talking about iOS here.

+5
source share
5 answers

Dot (.) - setter, getter. getter. , . Obj-C 2.0: " , , . " "". , , .

+6

.

:

  • , . setValue: , .value

  • , , . .

  • setXY: . .

+4

"" @property (, , ). , :

self.enabled = NO; // setter
BOOL isEnabled = self.enabled; // getter
self.selected = self.enabled = NO; // this is OK too
+3

.

.

Objective C [indexPath row], , [aTextField setText: @ "whatever" ]

. , .

Apple

Objective-C dot (.), , ([] s) .

myInstance.value = 10;
printf("myInstance value: %d", myInstance.value);

" " - ( ). :

[myInstance setValue:10]; printf("myInstance value: %d", [myInstance value]);
+1

!

. . . Objective-C 1.0, , , .

, , :

  • - , dot-syntax, !
  • - , , !
  • NO.

: - , , , doit ? :

  • ( -).
  • (/ -).

, , , . , , . , hidden, setHidden:animated:.

-2

All Articles