当前位置 : 主页 > 手机开发 > ios >

ios – 包括.pch文件中的公共头文件

来源:互联网 收集:自由互联 发布时间:2021-06-11
我只是想知道,在.pch文件中包含常用/最常用的头文件是不错的做法? 例如,标题下方需要大多数文件 #import UIKit/UIKit.h #import Foundation/Foundation.h 因此,不是每个文件都应该有,在.pch文件中添
我只是想知道,在.pch文件中包含常用/最常用的头文件是不错的做法?

例如,标题下方需要大多数文件

#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.

网友评论