I am fairly new with Objective C and getting my feet wet! I have came across with two different notations in syntax,
I would like to ask, Which would be more preferable? As I am learning this straight after java I am much more familiar with dot notation. So should consider it to be a normal pattern for whatever code I write? Does industry standardised which notation to use?
Thanks for your help
The dot notation is only available for properties and of course C structs. Whether you prefer:
foo.aProperty = bar.anotherProperty;
or:
[foo setAProperty:[bar anotherProperty]];
...is a matter of taste. I personally prefer the second one because it's absolutely clear there's two method calls involved. You can't tell at a first glance in this case:
CGFloat x = myView.frame.origin.x;
This is equivalent to:
CGFloat x = [myView frame].origin.x;
In the second example, it's clearly visible that a method call is involved, but the first example tends to be more readable.
So use whichever suits you, both are okay (though I guess most developers tend to use the first one, partly due to the fact it's faster to type and tends to be more legible).
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