re: Type introspection with NSMethodSignature, deprecated NSObjCValueType

  • > 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
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today