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

ios – 包括.pch文件中的公共头文件,第1张

概述我只是想知道,在.pch文件中包含常用/最常用的头文件是不错的做法? 例如,标题下方需要大多数文件 #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> 因此,不是每个文件都应该有,在.pch文件中添加这些文件是不错的做法? .pch文件 #ifdef __OBJC__ #import <UIKit/UIKit.h> 我只是想知道,在.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 @R_248_3013@ 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 @R_248_3013@ 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.

总结

以上是内存溢出为你收集整理的ios – 包括.pch文件中的公共头文件全部内容,希望文章能够帮你解决ios – 包括.pch文件中的公共头文件所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1017649.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存