In reference to this related question on stackoverflow:
If you create a constants file, how do you "link" to it in your target, so you don't have to
#import "Constants.h"
in every file you use constants?
In reference to this related question on stackoverflow:
If you create a constants file, how do you "link" to it in your target, so you don't have to
#import "Constants.h"
in every file you use constants?
You can put the import line in your pre-compiled header file. That is the .pch file named after you application name.
You really should be using #import "Constants.h"
every place you want to use the constants within it; Objective-C is a C-based language.
Furthermore, you aren't "linking" to it either when you put an #import
directive in your code or if you put one in your prefix file. In both cases, the contents of the file are included in the text stream fed to the compiler by the preprocessor.
Finally, you shouldn't generally add random things to your prefix file. (Panagiotis Korros referred to this as "your pre-compiled header file," but that's slightly incorrect; your prefix file is used to generate the pre-compiled header file.) If you keep your build settings consistent across projects, and use the same name for your prefix files across projects, Xcode will actually cache and re-use the precompiled versions for you very aggressively. This is defeated by putting project-specific contents in them.
I have a slightly different issue. I've made some extensions to NSArray by adding a category. So I have files NSArray+MyExtensions.h and its .m equivalent. How do I make these available to all my files and targets? I would prefer to add a new .pch file, perhaps, rather than adding these to the Project_prefix.pch file because I'm adding things all the time, and it takes a while to precompile the standard headers.