iOS Developer Library

Developer

Foundation Framework Reference NSMethodSignature Class Reference

Options
Deployment Target:

On This Page
Language:

NSMethodSignature

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. You typically create an NSMethodSignature object using NSObject’s methodSignatureForSelector: instance method (on OS X v10.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. More...

Inheritance


Conforms To


Import Statement


Not Applicable @import Foundation;

Availability


Available in iOS 2.0 and later.
  • Returns an NSMethodSignature object for the given Objective C method type string.

    Declaration

    Objective-C

    + (NSMethodSignature *)signatureWithObjCTypes:(const char *)types

    Parameters

    types

    An array of characters containing the type encodings for the method arguments.

    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.

    Return Value

    An NSMethodSignature object for the given Objective C method type string in types.

    Discussion

    Special Considerations

    This method, available since OS X v10.0, is exposed in OS X v10.5. Only type encoding strings of the style of the runtime that the application is running against are supported. In exposing this method there is no commitment to binary compatibly supporting any "old-style" type encoding strings after such changes occur.

    It is your responsibility to pass in type strings which are either from the current runtime data or match the style of type string in use by the runtime that the application is running on.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Objective-C

    - (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.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • The number of arguments recorded in the receiver. (read-only)

    Declaration

    Objective-C

    @property(readonly) NSUInteger numberOfArguments

    Discussion

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • The number of bytes that the arguments, taken together, occupy on the stack. (read-only)

    Declaration

    Objective-C

    @property(readonly) NSUInteger frameLength

    Discussion

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • A C string encoding the return type of the method in Objective-C type encoding. (read-only)

    Declaration

    Objective-C

    @property(readonly) const char *methodReturnType

    Discussion

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • The number of bytes required for the return value. (read-only)

    Declaration

    Objective-C

    @property(readonly) NSUInteger methodReturnLength

    Import Statement

    Availability

    Available in iOS 2.0 and later.

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

    Declaration

    Objective-C

    - (BOOL)isOneway

    Return Value

    YEStrue if the receiver is asynchronous when invoked through distributed objects, otherwise NOfalse.

    Discussion

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

    Import Statement

    Availability

    Available in iOS 2.0 and later.