Reputation: 11297
What is the difference between the two?
Upvotes: 2
Views: 3233
Reputation: 28572
A forward class declaration (class statement) simply tells the compiler a certain class exists, without specifying its methods, properties, etc. You can use a forward class declaration when you only need to declare a variable of that class, which is what you need in your header files most of the time. Then you will have to import the class in the implementation file.
Forward class declarations are particularly useful in resolving circular dependencies.
Check this out for more info:
Upvotes: 8
Reputation: 13807
The @class declaration is a way of telling the compiler that a particular class type exists without providing it with a full declaration of the class interface. This is useful when you want to refer to a class without disclosing/referencing methods which it exposes. In other words using a class declaration you can refer to a class in a header file and then delay the import of the implementation to your .m file.
Upvotes: 1