In Objective-c when we using object of one class into another class by convention we should forward declare the class in .h file, i.e. @class classname;. And should import the header file in .m file, i.e. #import "header.h".
But if we import the header file in .h then we don’t have to import it again in .m file .
So what is the reason behind this convention? Which is efficient way?
In Objective-c when we using object of one class into another class by convention
Share
You should favor forward declarations (
@class MONClass;) where possible because the compiler needs to know a typename is an objc class before it is used, and because an#importcan drag in a ton of other headers (e.g. entire frameworks/libraries), seriously expanding and complicating your dependencies and increasing your build times.Forward declarations. Your builds, rebuilds, and indexing will be much faster if you do this correctly.