Search code examples
iphoneobjective-cparametersnotation

Dot notation - Does it take parameters?


Is it correct if I say that

[anIstance aMethod];

is equivalent to

anIstance.aMethod; --?

If it is the case, what about methods which take one ore more parameters?

Does the following statement

[anIstance aMethod : aParameter];

have an equivalent dot notation?

I have tried with

anIstance.aMethod : aParameter;

anIstance.aMethod(aParameter);

And they don't seem to work (compile time errors)

If there is not a way to invoke a method with parameters in dot notation what about the synthesized setter methods (which, as far as I know, by definition take an argument)?

If I have a synthesized property, does the following statement

anIstance.aProperty = anotherObject;

invoke the relative setter method? Or does it call the getter method?


Solution

  • The other answers convey the general idea, but I'd like to explicitly state that dot notation and properties are separate concepts. Dot notation is intended for setters (methods named setSomething: that take a single parameter) and getters, and can also be used for any method that takes no parameters (though it's very poor style to use it for an action like myObject.doSomething).

    Properties are designed to declare getters and setters more easily, and even generate the code for you.

    So the two concepts are related, but it's entirely possible (and not always poor style) to use dot notation with your very own getters and setters, that you wrote by hand. It's also entirely possible (and usually perfectly acceptable!) to use properties, even with getters and setters generated for you, with normal bracket syntax, and not dot notation.

    But to address the original question, no, dot notation does not take parameters. It's specifically designed for use with methods that don't take parameters.