objective-ciphone-sdk-4.1

Where to #import on Objective-C


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:

  1. The .pch file (prefix)
  2. The .h file (header)
  3. 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:

  1. 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?
  2. 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 import there?

Solution

    1. 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.

    2. Read this question and answer.