Reputation: 67234
You're trying to use precompiled headers to "speed up compilation". Xcode has a file called YourProject_Prefix.pch
. You can include any number of header files in there that you like.
My question is, how do you select what header files should make it into your PCH? Should you just throw all your header files into there, or will that actually not be optimal?
Upvotes: 1
Views: 158
Reputation: 7534
the pch file will be included in all your source files by default.
that means you should really only put header files in there that are more or less global or never change. I believe putting all your headers in there would slow down compilation because every time you changed one it would cause every other file in your project to have to recompile. (I did not test or research this)
here is a sample from one of my projects:
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import "Errors.h"
#import "Localization.h"
#import "Logging.h"
#endif
Additionally, take the linked comments about C++ with a grain of salt. C++ uses templates and such that go in header files and make compilation take much longer than you are going to see in objective-c. in objective-c you are only likely to have types and interfaces, not implementation in a header.
Upvotes: 1
Reputation: 13783
Just import your header files there like the ones below.
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import "YourHeaderFile.h"
#endif
Pre-compiled headers, especially during building your app, can be very useful. The headers in the .pch file are only compiled the first time and then only if the headers change in the future. If your app imports many frameworks/headers that do not change; this could accelerate building (compiling) since the compiler will use the .pch versus compiling every imported framework/class every time you compile.
Upvotes: 1