Search code examples
objective-ctypedefobjective-c-category

ObjC category on typedef class: "cannot find interface declaration for 'typedefname'"


This code gives me the error Cannot find interface declaration for 'OGWView':

typedef SKNode OGWView;

@interface OGWView (Category)
@end

Why? Shouldn't the category work just as well with a typedef name?

PS: I know I can fix this with a #define (or by using the original class name) but I'm really more interested in understanding why it isn't possible to create a category on a typedef class.


Solution

  • I believe the answer to this question is that you have 2 different kinds of symbol. I believe the typedef is an object and you are trying to use it as a class symbol.

    depending on the order of declaration you get different warnings suggesting as much:

    typedef NSObject Foo;
    @class Foo;
    

    yields:

    Redefinition of forward class 'Foo' of a typedef name of an object type is ignored

    @class Foo;
    typedef NSObject Foo;
    

    yields:

    Redefinition of 'Foo' as different kind of symbol