Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dot Operator in Objective-C 2.0

Just picking up Objective-C 2.0 and wanted to know if there is any advantage in using the dot operator for accessing properties instead of the "old" way. Short example of what I mean.

"old" way:

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

"new" way:

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

Thanks!

Rodrigo

like image 243
therod Avatar asked Sep 12 '26 02:09

therod


2 Answers

The only difference is ease of typing and readability. The opinion of which is more readable differs from person to person :)

like image 158
Andrew Grant Avatar answered Sep 14 '26 17:09

Andrew Grant


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

Like so:

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

Instead of:

[[self view] setFrame:CGRectMake(0, 0, 320, 480)];
like image 27
Benjamin Autin Avatar answered Sep 14 '26 15:09

Benjamin Autin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!