My project has been increasing in size and I'm a little confused about where should I #import header files.
There are 3 main locations where I can import headers:
- The .pch file (prefix)
- The .h file (header)
- the .m file (implementation)
I don't care if the compiler takes more time to compile the files, all I care is that the end product is as fast as possible and uses the least amount of memory.
So, my questions are:
- If most files need a specific header, is it ok to add it to the .pch file, or is it more efficient to add it to just the required files?
- Should imports be done in the .h or .m file? I know I must add it to the .h file if i'm going to declare it there, but if I don't need to declare it in the .h file is there a problem of leaving the impor开发者_JAVA百科t there?
No, it is not ok to include it into the .pch file. This file is precompiled to every module in the project. Read about it here.
Read this question and answer.
Put your imports in your .m whenever you can. If you are using a class in your .h use @class
to forward the declaration, then #import
in your .m. The only time you should import in your .h are protocols that you implement or superclasses.
精彩评论