John gives good advice, but here is a bit more background on whys, wherefores and exceptions.
There are two goals to avoid importing headers into headers: improved incremental build times and avoiding circular dependencies. If you import Ah into Bh and import Bh into Ch , then every time you change something in Ah , you need to recompile Cm , even if Cm does not use any of the things defined in Ah . This can lead to a really terrible and unnecessary build failure, especially if you have headers that change frequently (as is common in the early stages of development).
The first goal is commendable, but for small projects, who cares? You have a quad-core Pro, and a complete build takes a couple of minutes, right? But you still have to worry about the second problem: circular dependencies. Ah references class B and Bh refer to class A This can actually happen quite often and can infiltrate the system completely innocently. A collection object can refer to the type of objects that it contains, and objects can refer to a type of a collection object. All that is required is a single reference due to some method that accepts or returns this type. If you have headers importing other headers, the likelihood of this quickly approaches unity. You complete the recursive import, and compile-time errors can be blurry. "I know that typdef is defined! It's right here! It's imported!" But it was not parsed when you imported this header. This is what causes the error above.
For this reason, even if you donβt have so much about build time (although you need it), avoid importing headers into headers ... except ....
Some headers to import. Of course, your superclass. Files that define @protocol that you implement, or typedef that you use. So yes, you must enable them.
What about system headers? Well, they are never going to cause rejection, and, obviously, they will not cause recursive imports, so everything is in order. I discourage people from using @class advanced ads for things in the system headers. This creates an extra user experience for your title without any value. For good heading hygiene, please remember to include system headings in <angle brackets> and your headings in quotation marks.
So this is not a trivial question, but a simple rule: avoid importing user headers into other user headers anytime the compiler allows you.
Rob napier
source share