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 |
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 Mac 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.
Returns an NSMethodSignature
object for the given Objective C method type string.
+ (NSMethodSignature *)signatureWithObjCTypes:(const char *)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
.
An NSMethodSignature
object for the given Objective C method type string in types.
This method, available since Mac OS X v10.0, is exposed in Mac 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.
NSMethodSignature.h
Returns the number of bytes that the arguments, taken together, occupy on the stack.
- (NSUInteger)frameLength
The number of bytes that the arguments, taken together, occupy on the stack.
This number varies with the hardware architecture the application runs on.
NSMethodSignature.h
Returns the type encoding for the argument at a given index.
- (const char *)getArgumentTypeAtIndex:(NSUInteger)index
The index of the argument to get.
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 applications should use it with caution.
NSMethodSignature.h
Returns a Boolean value that indicates whether the receiver is asynchronous when invoked through distributed objects.
- (BOOL)isOneway
YES
if the receiver is asynchronous when invoked through distributed objects, otherwise NO
.
If the method is oneway
, the sender of the remote message doesn’t block awaiting a reply.
NSMethodSignature.h
Returns the number of bytes required for the return value.
- (NSUInteger)methodReturnLength
The number of bytes required for the return value.
NSMethodSignature.h
Returns a C string encoding the return type of the method in Objective-C type encoding.
- (const char *)methodReturnType
A C string encoding the return type of the method in Objective-C type encoding.
This encoding is implementation-specific, so applications should use it with caution.
NSMethodSignature.h
Returns the number of arguments recorded in the receiver.
- (NSUInteger)numberOfArguments
The number of arguments recorded in the receiver.
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.
NSMethodSignature.h
© 2008 Apple Inc. All Rights Reserved. (Last updated: 2008-10-15)