What is an alternative to pch in swift? What is an alternative to pch in swift? xcode xcode

What is an alternative to pch in swift?


You cannot define "Macros" in swift, so there is no ".pch" file for swift.

Also, Swift doesn't have separate "Header (.h) and Implementation (.m)", so there is no need of predefined headers which are needed to compile.

For more information refer to this question, Why .pch file not available in 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.

Pods:

If you are using pods then it's necessary to import frameworks in every class where you are using.

Third Party Swift Frameworks:

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


There is no Swift equivalent for Objective-C .pch files.

Module is alternative for it.