1

I have a .h file with global variables, it's tedious to import this file over and over again. Is it possible to tell Xcode to import this always for every file in the project (except for it self I guess..)?

Johannes
  • 11,096
  • 20
  • 68
  • 85
  • 2
    You can import in your ProjectName-Prefix.pch file but I think that is not recommended. So if you have so many files to import in lots of controller's better make one header file like "CommonHeaders.h" and import all of them in that header file later you can just import "CommonHeaders.h". This might help http://stackoverflow.com/questions/2845211/ios-prefix-pch-best-practices – Pratik Mistry Aug 20 '14 at 13:30

1 Answers1

5

In xCode project you have a folder named 'Supporting Files' which contains a file:

PROJECTNAME-Prefix.pch

Just add import to those files and this file will be added by compiler to all of your files:

#ifdef __OBJC__
    #import <UIKit/UIKit.h>
    #import <Foundation/Foundation.h>
    #import "YourFile.h"
#endif

The disadvantage of this solution is that if you add lots of files or big files the compiling process will take more time.

Greg
  • 24,889
  • 6
  • 50
  • 62