0

Is there any way to import a common header for whole project only once? The idea is place on that header the #defines that will enable/disable functionalities.

I do not want to write #import "common.h" on every .m file.

Chris
  • 7,270
  • 19
  • 66
  • 110

3 Answers3

0

Yes, it is. Add your common file to the project:

enter image description here

Then edit the .pch file from your project and import your common.h file:

#ifdef __OBJC__
...
    #import "Common.h"
#endif

Finally the Common.h you can place the #defines:

#define FEATURE_A 0
#define FEATURE_B 1

ALL the stuff that you put in Common.h will be loaded automatically on your project.

0

Prefix headers are commonly used for this purpose; although some advocate against using them.

Reference: What is Prefix.pch file in Xcode?, http://qualitycoding.org/precompiled-headers/

Community
  • 1
  • 1
p0lAris
  • 4,750
  • 8
  • 45
  • 80
0

Follow Javier's answer, but you probably also need to create and set up your pch file now, as xcode doesn't automatically create it anymore. To do so, create a new file, select Other under iOS, and select PCH File. Name it ProjectNamePrefix.pch where ProjectName is your project's name.

Then after you create it, you need to go to your build settings, search for prefix. And under the section Apple LLVM 6.0 - Language you'll see a section called Prefix Header. Make the value of the file name you just created. Build, and your good.

Anything you import or define in this file will be available in all of your files

Chris
  • 7,270
  • 19
  • 66
  • 110