Quote:
Originally Posted by Bertrand21
You always #import the files you're using in your implementation, and if you need to reference a class in your header file use an @class forward declaration.
|
This is a partially correct description.
The @class keyword is used to
forward declare a class. You are not
required to #import the files needed in an implementation (IOW, you might be able to use the @class notation in an implementation). Also, if you need to reference a class in another header file, you aren't
required to use the @class notation (IOW, you can also simply #import the class header in your header file).
There's no actual
need for using the @class keyword. It's basically a way to tell the compiler about the
existence of a class, without bothering the compiler with all of the details of that class' implementation. Of course, you can only do this in places where the details of a class are insignificant.
I'm sure there could be a great debate as to why/when/how it should be used, but my experience and personal practice is to use forward declarations wherever possible to save a bit of compile time.