An NSMethodSignature object

p.p1 {margin: 0.0px 0.0px 10.0px 0.0px; font: 13.0px 'Lucida Grande'} span.s1 {font: 13.0px Courier; color: #666666} span.s2 {font: 13.0px Courier; color: #3466cc} span.s3 {color: #3466cc}

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 Programming Language.

你可能感兴趣的:(object,cmd,asynchronous,Types)