Objective-C method syntax

arguments, methods, objective-c, syntax

Solution

The default argument type is `id`. Even this will compile:

- testMethod:someArgument {
}

This is a method that takes an `id` as its argument and should return an `id`.

Actually, not even the method name is necessary:

- :someArgument {
}

This can be called as:

[self :someObject];

Of course all of this is very bad practice and you should always specify the types (and the names).

Problem

I was surprised when the following method definition compiled (using Apple LLVM 4.1): ``` - (void) testMethod:someArgument { } ``` Notice the type of `someArgument` is missing. What's the rule in Objective-C about specifying the types of method arguments?

Original source