You can use a prefix file to import classes in every classes. For example, if you have -
- somewhere in your prefix file, you don’t have to import UIKit manually in every file you need it. This is very useful for iOS apps since you’re going to want to have
UIKit available in most of your classes. The same goes for
It’s fast too.
“Prefix.pch is a precompiled header. Precompiled headers were invented to make compiling faster. Rather than parsing the same header files over and over, these files get parsed once, ahead of time.”
- RaffAl on Stack Overflow
To add one to your project, follow these instructions.
- Right click on your project name in Xcode.
- Scroll down to the
PCH Fileand click
- Name your file. The convention is
- Click on your project name.
- Go to your build settings.
- Go to the section named “Apple LLVM 9.0 - Language”.
- Click on Prefix Header
- Enter the value
Don’t put macros in your PCH file, it should only contain
#includes. If you need macros, you should define a
Common.h file and then import this file from your prefix file. Here’s an example of a
My prefix file looks like this in most of my projects.
Posted on 2018-03-27 #ios