xcode 什么是 swift 中 pch 的替代品?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31648610/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is an alternative to pch in swift?
提问by AiOsN
I was wondering what could be used instead of pch in swift.
我想知道在 swift 中可以用什么代替 pch 。
Is there any alternative to pch or way to get rid of import in swift so that we don't need to do this for all classes.
是否有任何替代 pch 或方法可以快速摆脱导入,以便我们不需要对所有类都执行此操作。
I don't want to carry around/import all the time. What could be the best substitute of pch in swift.
我不想一直随身携带/进口。什么可能是 swift 中 pch 的最佳替代品。
回答by Sohil R. Memon
You cannot define "Macros" in swift, so there is no ".pch" file for swift.
您不能在 swift 中定义“宏”,因此 swift 没有“.pch”文件。
Also, Swift doesn't have separate "Header (.h) and Implementation (.m)", so there is no need of predefined headers which are needed to compile.
此外,Swift 没有单独的“头文件 (.h) 和实现 (.m)”,因此不需要编译所需的预定义头文件。
For more information refer to this question, Why .pch file not available in swift?
有关更多信息,请参阅此问题,为什么 .pch 文件在 swift 中不可用?
Class Import Problem:
类导入问题:
In Swift, you don't need to write "import" statement for your project classes everywhere. You can access the project classes just by creating their objects.
在 Swift 中,你不需要在任何地方为你的项目类编写“import”语句。您可以通过创建对象来访问项目类。
Pods:
豆荚:
If you are using pods then it's necessary to import frameworks in every class where you are using.
如果您正在使用 pod,那么有必要在您使用的每个类中导入框架。
Third Party Swift Frameworks:
第三方 Swift 框架:
For external Frameworks/Modules, you can create a bridging header file and replace the below line with your framework/module name:
对于外部框架/模块,您可以创建一个桥接头文件并将以下行替换为您的框架/模块名称:
@import ModuleName;
Reference: Implicitly import specific Swift module
回答by Nilesh Patel
There is no Swift equivalent for Objective-C .pch
files.
Objective-C.pch
文件没有 Swift 等价物。
Module
is alternative for it.
Module
是它的替代品。