Methods without Argument Names

When creating the name for a method, the argument names are actually optional. For example, you can declare a method like this:

-(int) set: (int) n: (int) d;

Note that, unlike in previous examples, no name is given for the second argument to the method here. This method is named set::, and the two colons mean the method takes two arguments, even though they’re not all named.

To invoke the set:: method, you use the colons as argument delimiters, as shown here:

[aFraction set:1 :3];

It’s not good programming style to omit argument names when writing new methods because it makes the program harder to follow and makes the purpose of the method’s actual parameters less intuitive.

Get Programming in Objective-C, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.