NSMethod object records type information for the return value and parameters of a method. It is used to forward messages that the receiving object does not respond to—most notably in the case of distributed objects.
You typically create an
NSMethod object using the
method instance method (in macOS 10.5 and later you can also use
signature). It is then used to create an
NSInvocation object, which is passed as the argument to a
forward message to send the invocation on to whatever other object can handle the message. In the default case,
does, which raises an exception. For distributed objects, the
NSInvocation object is encoded using the information in the
NSMethod object and sent to the real object represented by the receiver of the message.
NSMethod object is initialized with an array of characters representing the string encoding of return and argument types for a method. You can get the string encoding of a particular type using the
@encode() compiler directive. Because string encodings are implementation-specific, you should not hard-code these values.
A method signature consists of one or more characters for the method return type, followed by the string encodings of the implicit arguments
_cmd, followed by zero or more explicit arguments. You can determine the string encoding and the length of a return type using
method properties. You can access arguments individually using the
get method and
For example, the
NSString instance method
contains has a method signature with the following arguments:
c) for the return type
@) for the receiver (
:) for the selector (
@) for the first explicit argument