CodeSmile
CodeSmile

Reputation: 64477

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.

Upvotes: 3

Views: 1765

Answers (2)

Yousef Hamza
Yousef Hamza

Reputation: 375

Replace typedef with @compatibility_alias

@compatibility_alias SKNode OGWView;

Upvotes: 3

Brad Allred
Brad Allred

Reputation: 7534

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

Upvotes: 3

Related Questions