An NSMethodSignature 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 NSMethodSignature object using the NSObject methodSignatureForSelector: instance method (in macOS 10.5 and later you can also use signatureWithObjCTypes:). It is then used to create an NSInvocation object, which is passed as the argument to a forwardInvocation: message to send the invocation on to whatever other object can handle the message. In the default case, NSObject invokes doesNotRecognizeSelector:, which raises an exception. For distributed objects, the NSInvocation object is encoded using the information in the NSMethodSignature object and sent to the real object represented by the receiver of the message.

Type Encodings

An NSMethodSignature 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 self and _cmd, followed by zero or more explicit arguments. You can determine the string encoding and the length of a return type using methodReturnType and methodReturnLength properties. You can access arguments individually using the getArgumentTypeAtIndex: method and numberOfArguments property.

For example, the NSString instance method containsString: has a method signature with the following arguments:

  1. @encode(BOOL) (c) for the return type

  2. @encode(id) (@) for the receiver (self)

  3. @encode(SEL) (:) for the selector (_cmd)

  4. @encode(NSString *) (@) for the first explicit argument

See Type Encodings in Objective-C Runtime Programming Guide for more information.


Creating a Method Signature Object

+ signatureWithObjCTypes:

Returns an NSMethodSignature object for the given Objective-C method type string.

Getting Information on Argument Types

- getArgumentTypeAtIndex:

Returns the type encoding for the argument at a given index.


The number of arguments recorded in the receiver.


The number of bytes that the arguments, taken together, occupy on the stack.

Getting Information on Return Types


A C string encoding the return type of the method in Objective-C type encoding.


The number of bytes required for the return value.

Determining Synchronous Status

- isOneway

Whether the receiver is asynchronous when invoked through distributed objects.


Inherits From