Apple Developer Connection
Member Login Log In | Not a Member? Contact ADC

Next Page > Hide TOC

NSMethodSignature Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/Foundation.framework
Availability
Available in Mac OS X v10.0 and later.
Declared in
NSMethodSignature.h
Companion guides

Overview

An NSMethodSignature object records type information for the arguments and return value 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. An NSMethodSignature object is typically created using NSObject’s methodSignatureForSelector: instance method. 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.

An NSMethodSignature object 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 object 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 “How Messaging Works” in “The Language” in The Objective-C 2.0 Programming Language.

Tasks

Getting Information on Argument Types

Getting Information on Return Types

Determining Synchronous Status

Instance Methods

frameLength

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

- (NSUInteger)frameLength

Return Value

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

Discussion

This number varies with the hardware architecture the application runs on.

Availability
Declared In
NSMethodSignature.h

getArgumentTypeAtIndex:

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

- (const char *)getArgumentTypeAtIndex:(NSUInteger)index

Parameters
index

The index of the argument to get.

Return Value

The type encoding for the argument at index.

Discussion

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 applications should use it with caution.

Availability
Declared In
NSMethodSignature.h

isOneway

Returns a Boolean value that indicates whether the receiver is asynchronous when invoked through distributed objects.

- (BOOL)isOneway

Return Value

YES if the receiver is asynchronous when invoked through distributed objects, otherwise NO.

Discussion

If the method is oneway, the sender of the remote message doesn’t block awaiting a reply.

Availability
Declared In
NSMethodSignature.h

methodReturnLength

Returns the number of bytes required for the return value.

- (NSUInteger)methodReturnLength

Return Value

The number of bytes required for the return value.

Availability
See Also
Declared In
NSMethodSignature.h

methodReturnType

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

- (const char *)methodReturnType

Return Value

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

Discussion

This encoding is implementation-specific, so applications should use it with caution.

Availability
See Also
Declared In
NSMethodSignature.h

numberOfArguments

Returns the number of arguments recorded in the receiver.

- (NSUInteger)numberOfArguments

Return Value

The number of arguments recorded in the receiver.

Discussion

There are always at least 2 arguments, because an NSMethodSignature object includes the hidden arguments self and _cmd, which are the first two arguments passed to every method implementation.

Availability
Declared In
NSMethodSignature.h

Next Page > Hide TOC


Last updated: 2008-03-11




Did this document help you?
Yes: Tell us what works for you.

It’s good, but: Report typos, inaccuracies, and so forth.

It wasn’t helpful: Tell us what would have helped.
Get information on Apple products.
Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Copyright © 2007 Apple Inc.
All rights reserved. | Terms of use | Privacy Notice