Prefix Headers and Precompiled Headers (.pch)
History:
[#include -> #import] -> Precompiled Headers .pch -> [@import Module(ObjC);] -> [import Module(Swift)]
Precompiled Headers - prefix.pch
To create new .pch file
File -> New -> File... -> PCH File
PrefixHeader.pch
sample:
#ifndef PrefixHeader_pch
#define PrefixHeader_pch
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
From Xcode 6 you should set .pch
manually. Previously it was called <product_name>-Prefix.pch
Xcode:
Prefix Header(GCC_PREFIX_HEADER)
- path to .pch
. Adds all content from .pch
to all source files
SomeFile1.h
//You can skip this section. It will be compiled
//#import <UIKit/UIKit.h>
//#import <Foundation/Foundation.h>
//implicitly next line is used
#import "PrefixHeader.pch"
Precompile Prefix Header(GCC_PRECOMPILE_PREFIX_HEADER)
- When Yes then Prefix headers
from GCC_PREFIX_HEADER
will be used once* to generate precompiled sources and will be stored in a cache which speeds up a build time
//path to cached precompiled headers
/<some_path>/DerivedData/ExperiementsModuleSwift-dsetoksxykdmgvczgtnmaqmjwhzk/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14385052922615550324
//e.g
/Users/alex/Library/Developer/Xcode/DerivedData/ExperiementsModuleSwift-dsetoksxykdmgvczgtnmaqmjwhzk/Build/Intermediates.noindex/PrecompiledHeaders/SharedPrecompiledHeaders/14385052922615550324
#import vs .pch
This feature improves build time(comparing with #include/#import
) because precompiles a prefix headers
(global). When some content of prefix headers
is changed it means that Compiles must recompile that again. that is why you should use stable(not often changeable) prefix headers
here or you dont't see build time improvement. Also you should support it