NSMethodSignature Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/Foundation.framework |
| Availability | Available in iOS 2.0 and later. |
| Declared in | NSMethodSignature.h |
| Companion guides | Distributed Objects Programming Topics The Objective-C 2.0 Programming Language |
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. 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.
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 Objective-C 2.0 Programming Language.
Tasks
Creating a Method Signature Object
Getting Information on Argument Types
Getting Information on Return Types
Determining Synchronous Status
Class Methods
signatureWithObjCTypes:
Returns an NSMethodSignature object for the given Objective C method type string.
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 indices0and1; method-specific arguments begin at index2.
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 compatibily 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.
Availability
- Available in iOS 2.0 and later.
Declared In
NSMethodSignature.hInstance Methods
frameLength
Returns the number of bytes that the arguments, taken together, occupy on the stack.
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
- Available in iOS 2.0 and later.
Declared In
NSMethodSignature.hgetArgumentTypeAtIndex:
Returns the type encoding for the argument at a given 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
- Available in iOS 2.0 and later.
Declared In
NSMethodSignature.hisOneway
Returns a Boolean value that indicates whether the receiver is asynchronous when invoked through distributed objects.
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
- Available in iOS 2.0 and later.
Declared In
NSMethodSignature.hmethodReturnLength
Returns the number of bytes required for the return value.
Return Value
The number of bytes required for the return value.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
NSMethodSignature.hmethodReturnType
Returns a C string encoding the return type of the method in Objective-C type encoding.
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
- Available in iOS 2.0 and later.
See Also
Declared In
NSMethodSignature.hnumberOfArguments
Returns the number of arguments recorded in the receiver.
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
- Available in iOS 2.0 and later.
Declared In
NSMethodSignature.h© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)