tags:

views:

60

answers:

2

Until now, I believed that -(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing has the following "method signature", which is at the same time also the selector: -startToDoSomethingWithThis:andThat:

But now someone said that the selector is not like the method signature, and that the method signature also contains the arguments and their types. Is that correct?

+3  A: 

A selector is the name of a method within a class. It is used to identify the method, most often when it is being called. A signature is a description of argument and return types. It is used when calling an arbitrary method, for example by NSInvocation, to arrange arguments and make room for the return value. Many selectors may have the same signature.

SEL aSelector = @selector(method:foo:);
NSMethodSignature *aSignature = [theObject methodSignatureForSelector:aSelector];

NSMethodSignature is a wrapper around objc_method_description types.

drawnonward
So the "method signature" does consist of the arguments and their types as well as of the return type of the method?
dontWatchMyProfile
+2  A: 

That's correct. A selector is the method name. A method signature is an encapsulation of the return type and argument types. You can introspect method signatures using +[NSObject instanceMethodForSelector:], which returns an NSMethodSignature object.

Dave DeLong
An `NSMethodSignature` does not record the selector it is related to.
drawnonward
@drawnonward thanks for correcting me. edited answer.
Dave DeLong