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?
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).
Language specification states:
If a return or parameter type isn’t explicitly declared, it’s assumed to be the default type for methods and messages—an id.
http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/objectivec/chapters/ocDefiningClasses.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With