16

I was wondering what could be used instead of pch in swift.

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.

I don't want to carry around/import all the time. What could be the best substitute of pch in swift.

AiOsN
  • 2,305
  • 2
  • 23
  • 29

2 Answers2

24

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

Community
  • 1
  • 1
Sohil R. Memon
  • 9,404
  • 1
  • 31
  • 57
1

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

Module is alternative for it.

Nilesh Patel
  • 6,318
  • 1
  • 26
  • 40