例如,标题下方需要大多数文件
#import <UIKit/UIKit.h> #import <Foundation/Foundation.h>
因此,不是每个文件都应该有,在.pch文件中添加这些文件是不错的做法?
.pch文件
#ifdef __OBJC__ #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> #import <MostlyUsed.h> #endif
我发现了一些这样的缺点,
1)依赖隐藏.
2)源文件无法直接复制.
如果你们提供一些意见,这将是很好的.
谢谢
是的,你可以做到.即使它减少了编译时间.
In Objective-C, importing same headers in every class make compile time longer?的摘录
In general, newly-generated iOS projects come with this functionality,
which is called a precompiled header or prefix header, and is a file
that has the extension .pch.You can throw all the headers you want in there and Xcode will
pre-compile it before it builds anything else, and use it to compile
the other compilation units in your project (e.g. .m files).Using a precompiled header may or may not increase compile time; in
general, it reduces compile time, as long as you have a lot of common
headers and/or a lot of source files.However, it’s not necessarily good practice to treat the pre-compiled header like a big dumping ground, as your compilation units can form implicit dependencies on all sorts of stuff when you may want to enforce loose coupling between components.