In Objective-C, we can name methods with arguments in the middle. So when he writes [myFraction setTo:100 over:200];
, the over
could mean... well, whatever he wants. It's part of the method name he chose. In this case, he was probably trying to make the method sound like English. ("Set this fraction to 100 over 200." We read fractions as "numerator over denominator" often in normal speech.)
Some methods, called "accessors", we write very frequently: these are methods of the form - (int)variable
(called "getters"), and - (void)setVariable:(int)newValue
(called "setters"). My examples here would assumedly return, or change, respectively, an instance variable called variable
. Here's what the method implementations might look like:
- (int)variable
{
return variable;
}
- (void)setVariable:(int)newValue
{
variable = newValue;
}
It's common to have accessors like this for almost every instance variable your class has. At some point, someone got tired of writing [myInstance setVariable:20];
and such, and decided they'd rather it look like many other languages out there, myInstance.variable = 20;
.
Therefore, Objective-C 2.0 added dot notation, which allows you to write...
myInstance.variable
, which is exactly equivalent to [myInstance variable]
in most circumstances (and does NOT access the instance variable variable
directly!), and...
the special case myInstance.variable = 20;
, which is exactly equivalent to [myInstance setVariable:20];
. Again, note that this does not access variable
directly, it sends a message to myInstance
. So if we'd written some other code in setVariable
, it would still be accessed if we used dot notation.
Dot notation is designed to be used for accessors. You could also theoretically use it for any method that returns a value and takes no arguments (myArray.count
, for example). Using it for anything else (myInstance.doSomeAction
) is extremely poor style. Don't do it. Therefore, as I'm sure you can guess by now, [myFraction setTo:100 over:200]
has no dot notation equivalent, as it takes 2 arguments, and isn't an accessor.