Is there any difference in doing
@class MyViewController;
rather than doing the normal import of the .h into the appdelegate.h
#import "MyViewController.h"
I’ve seen some example recently that use the @class way and wondered if there any differences.
thanks.
There is a big difference.
Is a forward declaration for the object
MyViewController. It is used when you just need to tell the compiler about an object type but have no need to include the header file.If however you need to create an object of this type and invoke methods on it, you will need to:
But normally this is done in the
.mfile.An additional use of forward declarations is when you define a
@protocolin the same header file as an object that uses it.In the above example the compiler needs to know that the
@protocol MyProtocolDelegateis valid before it can compile theMyObjectobject.Simply moving the protocol definition above
MyObjectdefinition would also work.