@class
is called a forward declaration. You're basically telling the compiler that the class exists but not anything about the class. Thus, it doesn't know stuff like its superclass and what methods it declares.
As a general rule, use @class
in the .h and #import
in the .m, if at all possible. Like Louis said, it'll help speed up compile times. There are times when you need to #import
a class in the header, though. Cases I can think of right now are:
- You are subclassing another class
- You are implementing a protocol
In these cases, you must #import
the header file where the class or protocol is declared because the compiler needs to know the full class hierarchy of its parent classes and implementing protocols.
FWIW, you can forward declare protocols, too, so long as your not implementing them:
@protocol SomeProtocol;
@interface ...
- (id<SomeProtocol>)someMethod;
@end