Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bizzare method signature, with unnamed arguments (obj-c)

I wasn't aware this syntax was valid.

+ (void) methodName:(TypeObject *)typeObject1:(TypeObject *)typeObject2;

Which is then called like so:

[object methodName:obj1:obj2];

I find it ugly and disturbing, but it builds.

Can someone point me at a reference which explains why this is valid.

FWIW the codebase (inherited) that this comes from, is rife with sloppy, lazy stuff, dozens of spelling errors and looks like it was formatted by someone with no need to ever read it again. (Thank you again uncrustify.)

like image 870
ocodo Avatar asked Feb 18 '23 10:02

ocodo


1 Answers

This is a well-kown and documented feature (pdf, p. 14)

In principle, a Rectangle class could instead implement a setOrigin:: method with no label for the second parameter, which would be invoked as follows:

[myRectangle setOrigin:30.0 :50.0]; // This is a bad example of multiple parameters

but apple discourage everbody of using parameter passing without keyword:

Use keywords before all arguments.
- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag; -> Right.
- (void)sendAction:(SEL)aSelector :(id)anObject :(BOOL)flag; -> Wrong.

Why it was allowed by the creators of objective-C, I dont know. Maybe it has to do with the Smalltalk heritage.

like image 111
vikingosegundo Avatar answered Mar 04 '23 00:03

vikingosegundo