What is the difference between a method signature and a selector in Objective-C?

So far, I thought that -(void)startToDoSomethingWithThis:(That*)thing andThat:(That*)otherThing has the following "method signature", which at the same time is a selector: -startToDoSomethingWithThis:andThat:

But now someone said that the selector is not like the signature of a method, and that the signature of a method also contains arguments and their types. It is right?

+4
objective-c
Jun 22 '10 at 16:19
source share
2 answers

A selector is the name of a method inside a class. It is used to identify a method, most often when called. A signature is a description of the arguments and return types. It is used when calling an arbitrary method, such as NSInvocation, to organize arguments and free up space for the return value. Many selectors can have the same signature.

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

NSMethodSignature is a wrapper for objc_method_description types.

+8
Jun 22 '10 at 16:29
source share

It is right. The selector is the name of the method. A method signature is an encapsulation of return type types and arguments. You can introspect method signatures using +[NSObject instanceMethodForSelector:] , which returns NSMethodSignature .

+5
Jun 22 '10 at 16:30
source share



All Articles