Bizzare Method Signature with Unnamed Arguments (obj-c)

I did not know that this syntax is valid.

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

What is called like this:

 [object methodName:obj1:obj2]; 

I find this ugly and disturbing, but he is building.

Can someone point me to a link that explains why this is true.

FWIW, the codebase (inherited) from which it comes from, is replete with sloppy, lazy material, dozens of spelling errors and looks like it was formatted by someone who didn't need to read it again. (Thanks again to uncrustify .)

+4
source share
1 answer

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

Basically, the Rectangle class can instead implement the setOrigin:: method without a label for the second parameter, which will be called as follows:

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

but apple prevents using parameter passing without a keyword :

Use keywords before all arguments.
- (void)sendAction:(SEL)aSelector to:(id)anObject forAllCells:(BOOL)flag; → To the right.
- (void)sendAction:(SEL)aSelector :(id)anObject :(BOOL)flag; → Wrong.

Why this was allowed by the creators of objective-C, I do not know. Perhaps this is due to the heritage of Smalltalk.

+8
source

Source: https://habr.com/ru/post/1447380/


All Articles