I’m a beginner of Objective-C/iOS programing.
I want make a one header file which includes all class headers I use in my project.
And import the header in every class header file.
Like this question:
Including multiple classes in the same header file
But does this approach increase compile time?
Or are there any other disadvantage?
Please tell me the good ways to import headers.
In general, newly-generated iOS projects come with this functionality, which is called a precompiled 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.
.mfiles).Using a precompiled 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.