In Objective-C, importing same headers in every class make compile time longer?

前端 未结 5 529
轻奢々
轻奢々 2021-01-11 17:23

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

5条回答
  •  渐次进展
    2021-01-11 17:42

    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. .m files).

    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.

提交回复
热议问题