Point Operator in Objective-C 2.0

Just select Objective-C 2.0 and want to know if there is an advantage to using the point operator to access properties instead of the "old" way. A short example of what I mean.

"old" way:

 [myFraction setNumerator: 1];
 [myFraction setDenominator: 3];

"new" way:

 myFraction.numerator = 1;
 myFraction.denominator = 3;

Thanks!

Rodrigo

+3
source share
5 answers

The only difference is the ease of typing and reading. The opinion of which is more readably different from person to person :)

+7
source

I use dot syntax when I omit an object and use a bracket to actually set the property.

Same:

[self.view setFrame:CGRectMake(0, 0, 320, 480)];

Instead:

[[self view] setFrame:CGRectMake(0, 0, 320, 480)];
+2
source

, , , , Python.

dot-property KVC/KVO. , ( , !) , , , - .

, ( ) , , .

+2

:

, Objective-C, , C struct ( ).

, / .

+1
source

C ++ and C # programmers are likely to more naturally adapt to the dot operator when accessing member variables, since it has a similar use in these languages.

0
source

Source: https://habr.com/ru/post/1704242/


All Articles