<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.0.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMethodSignature",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSMethodSignature"
  },
  "title" : "NSMethodSignature"
}
-->

# NSMethodSignature

A record of the type information for the return value and parameters of a method.

```
@interface NSMethodSignature : NSObject
```

## Overview

Use an [`NSMethodSignature`](/documentation/Foundation/NSMethodSignature) object to forward messages that the receiving object does not respond to—most notably in the case of distributed objects. You typically create an [`NSMethodSignature`](/documentation/Foundation/NSMethodSignature) object using the <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class> <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/methodSignatureForSelector:> instance method (in macOS 10.5 and later you can also use [`signatureWithObjCTypes:`](/documentation/Foundation/NSMethodSignature/signatureWithObjCTypes:)). It is then used to create an [`NSInvocation`](/documentation/Foundation/NSInvocation) object, which is passed as the argument to a <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/forwardInvocation:> message to send the invocation on to whatever other object can handle the message. In the default case, <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class> invokes <doc://com.apple.documentation/documentation/ObjectiveC/NSObject-swift.class/doesNotRecognizeSelector(_:)>, which raises an exception. For distributed objects, the [`NSInvocation`](/documentation/Foundation/NSInvocation) object is encoded using the information in the [`NSMethodSignature`](/documentation/Foundation/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`](/documentation/Foundation/NSMethodSignature/methodReturnType) and [`methodReturnLength`](/documentation/Foundation/NSMethodSignature/methodReturnLength) properties. You can access arguments individually using the [`getArgumentTypeAtIndex:`](/documentation/Foundation/NSMethodSignature/getArgumentTypeAtIndex:) method and [`numberOfArguments`](/documentation/Foundation/NSMethodSignature/numberOfArguments) property.

For example, the `NSString` instance method [`contains(_:)`](/documentation/Foundation/NSString/contains(_:)) 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](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html#//apple_ref/doc/uid/TP40008048-CH100) in [Objective-C Runtime Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008048) for more information.

## Topics

### Creating a Method Signature Object

[`signatureWithObjCTypes:`](/documentation/Foundation/NSMethodSignature/signatureWithObjCTypes:)

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

### Getting Information on Argument Types

[`getArgumentTypeAtIndex:`](/documentation/Foundation/NSMethodSignature/getArgumentTypeAtIndex:)

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

[`numberOfArguments`](/documentation/Foundation/NSMethodSignature/numberOfArguments)

The number of arguments recorded in the receiver.

[`frameLength`](/documentation/Foundation/NSMethodSignature/frameLength)

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

### Getting Information on Return Types

[`methodReturnType`](/documentation/Foundation/NSMethodSignature/methodReturnType)

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

[`methodReturnLength`](/documentation/Foundation/NSMethodSignature/methodReturnLength)

The number of bytes required for the return value.

### Determining Synchronous Status

[`isOneway`](/documentation/Foundation/NSMethodSignature/isOneway)

Whether the receiver is asynchronous when invoked through distributed objects.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)