Skip navigation.
 
mlre: Type introspection with NSMethodSignature, deprecated NSObjCValueType
FROM : Ben Trumbull
DATE : Fri Feb 01 22:08:21 2008

>Suppose I want to verify that a given method signature looks like an
>action method.
>
>if ([methodSignature numberOfArguments] == 3 &&
>    0 == strcmp(@encode(void), [methodSignature methodReturnType]) &&
>    0 == strcmp(@encode(id), [methodSignature getArgumentTypeAtIndex: 2]) {
>
>}
>
>Is testing the argument types in this manner, with @encode(), going to
>be future proof?


No, I don't believe strcmp() will be future proof.  Depending on how
the method is declared, and which version of the compiler you use,
I've gotten very different results for object types:

static BOOL isTypeEncodingObject(char* enctext) {
    // @                            id
    // @"Foobar"                    Foobar*
    // ^#                          Class* aka id
    // ^{Foobar=# .... }            Foobar* with ivar decls.  Antiquated.

...

It might be that for an application, asking about it's own methods
(presumably all compiled at the same time with the same compiler)
you'd be fine.  Not sure about that, but it's clearly not the case
for a framework.
--

-Ben

Related mailsAuthorDate
No related mails found.