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..)?

  • 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

4

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
  • 25,317
  • 6
  • 53
  • 62
  • Thanks! It's not a problem to import a file several times is it? –  Aug 20 '14 at 13:31
  • The compiling process was not a problem, I could run the project as fast as ever. –  Aug 20 '14 at 13:32
  • 1
    If you use #import compiler make sure that this file is added just once to every file. – Greg Aug 20 '14 at 13:33