NSMethodSignature class
NSMethodSignature provides information about the type signature
of a method. The Objective-C type encoding of a method is a C string
that contains an encoding of the return value type and type of the
arguments including information about how to access them on the stack
and registers frames. See the Objective-C documentation in the GCC
runtime for more information about method type encoding.
Below is an example of how to create a NSMethodSignature instance
for a given method of an object:
id anObject;
struct objc_method* mth
= class_get_instance_method(self->isa, aSelector);
const char* types = mth->method_types;
id signature = [NSMethodSignature signatureWithObjCTypes:types];
The above code is implemented by the NSObject's
methodSignatureForSelector: method. If you send this method to a
class, the method searches for a class method whose selector is the same
as the argument. If the message is sent to an instance, the method
searches for an instance method. If you don't want to create an instance
of a class just to find out what is the signature of an instance method,
you can use the instanceMethodForSelector: method, that searches
in the class for an instance method with the same selector as the
argument.
In addition to providing information about already existing method
encodings that are available for compiled methods, the
NSMethodSignature class from libFoundation allows you to
construct method signatures for new methods, that could be created for
example by an interpreter. Suppose one wants to create a method encoding
that has arguments an integer and its return type is void; you
can do like this:
id signature = [NSMethodSignature signatureWithObjCTypes:"vi"];
The NSMethodSignature class computes the full signature that
contains the offsets of the arguments on the stack and registers
frames. This code is dependent on the target machine so the result may
be different between various processors and even on the same processor
but different OSes.
Go to the first, previous, next, last section, table of contents.