Consider the following method:
+(void) myMethod:(int)arg1 **argument2**(int)arg2 **argument3**(int) arg3;
See how the first argument, unlike the 2nd and 3rd, doesn't have a description, giving it an impression of bad symmetry. Also you would expect the extra typing will provide named argument as you pass it in, but you still have to pass them in the correct order.
Can anyone help me make sense of this?
You're missing :
after argument2
and argument3
Also, first argument is named myMethod
. By Apple's naming recommendation guide, you'd see the method should be named in the manner that identifies semantics of first argument.
EDIT:
check out this document Coding Guidelines - Naming Methods
Hopefully the response to this other question will help you make sense of what you see.
The logic behind this exists though hard to get used to.
regarding your first note, about the naming of the first param,
Apple encourage you to name your methods as follows:
+(void)myMethodWithArg1:(int)arg1 Arg2:(int)arg2 Arg3:(int)arg3;
thus making the name readable like a sentence in english
(my method had Arg1 of type int, Arg2 of type int, etc)
regarding the named params and the inability to change the order, that makes no sence to me either
and the comment above me is correct, you are missing those annoying : after the params
In addition, the syntax of ObjC has strong relation to that of Smalltalk (http://www.smalltalk.org/main/)
I'd encourage you to read on that and the relation between the two languages
hope this helps
The method name is supposed to described the first argument.
Like:
+ (void)updateUserWithId:id andAge:age
So that the whole expression gives sort of a natural sentence.
精彩评论