Documentation Archive Developer
Search

NSMethodSignature

Inherits From:
NSObject

Conforms To:
NSObject (NSObject)

Declared In:
Foundation/NSMethodSignature.h

Class Description

An NSMethodSignature records type information for the arguments and return value of a method. It's used to forward messages that the receiving object doesn't respond to-most notably in the case of distributed objects. An NSMethodSignature is typically created using NSObject's methodSignatureForSelector: instance method. It's then used to create an NSInvocation, 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 is encoded using the information in the NSMethodSignature and sent to the real object represented by the receiver of the message.

An NSMethodSignature presents its argument types by index with the getArgumentTypeAtIndex: method. The hidden arguments for every method, self and _cmd, are at indices 0 and 1 respectively. The arguments normally specified in a message invocation follow these. In addition to the argument types, an NSMethodSignature offers the total number of arguments with numberOfArguments, the total stack frame length occupied by all arguments with frameLength (this varies with hardware architecture), and the length and type of the return value with methodReturnLength and methodReturnType. Finally, applications using distributed objects can determine if the method is asynchronous with the isOneway method.

For more information about the nature of a method, including the hidden arguments, see Object-Oriented Programming and the Objective-C Language.


Method Types

Querying attributes
- frameLength
- getArgumentTypeAtIndex:
- isOneway
- numberOfArguments
- methodReturnLength
- methodReturnType

Instance Methods

getArgumentTypeAtIndex:

- (const char *)getArgumentTypeAtIndex:(unsigned int)index

Returns the type encoding for the argument at index. Indices begin with 0. The hidden arguments self (of type id) and _cmd (of type SEL) are at indices 0 and 1; method-specific arguments begin at index 2. Raises NSInvalidArgumentException if index is too large for the actual number of arguments.

Argument types are given as C strings with Objective-C type encoding. This encoding is implementation-specific, so OpenStep applications should use it with caution.


frameLength

- (unsigned int)frameLength

Returns the number of bytes that the arguments, taken together, occupy on the stack. This number varies with the hardware architecture the application runs on.


isOneway

- (BOOL)isOneway

Returns YES if the method is asynchronous when invoked through distributed objects. In this case the sender of the remote message doesn't block awaiting a reply. Returns NO otherwise.


methodReturnLength

- (unsigned int)methodReturnLength

Returns the number of bytes required for the return value.

See also: - methodReturnType


methodReturnType

- (char *)methodReturnType

Returns a C string encoding the return type of the method in Objective-C type encoding. This encoding is implementation-specific, so OpenStep applications should use it with caution.

See also: - methodReturnLength


numberOfArguments

- (unsigned int)numberOfArguments

Returns the number of arguments recorded in the NSMethodSignature. This is at least 2, since an NSMethodSignature includes the hidden arguments self and _cmd, which are the first two arguments passed to every method implementation.

Copyright © 1997, Apple Computer, Inc. All rights reserved.