This section documents the encoding of method types, which is rarely needed to use Objective-C. You should skip it at a first reading; the runtime provides functions that will work on methods and can walk through the list of parameters and interpret them for you. These functions are part of the public “API” and are the preferred way to interact with method signatures from user code.
But if you need to debug a problem with method signatures and need to know how they are implemented (i.e., the “ABI”), read on.
Methods have their “signature” encoded and made available to the runtime. The “signature” encodes all the information required to dynamically build invocations of the method at runtime: return type and arguments.
The “signature” is a null-terminated string, composed of the following:
selfand the method selector
For example, a method with no arguments and returning
would have the signature
if the size of a pointer is 4. The signature is interpreted as follows: the
is the return type (an
is the total size of the parameters in bytes (two pointers each of size 4), the
is the first parameter (an object at byte offset
is the second parameter (a
at byte offset
You can easily find more examples by running the “strings” program on an Objective-C object file compiled by GCC. You'll see a lot of strings that look very much like
. They are signatures of Objective-C methods.