Inclusion of the foundation header - and precompiled headers


In the beginning of the chapter, you write:

“Note that we don’t import Foundation.h. How then can we use NSMutableArray? In this template, the Foundation Framework header is part of the precompiled header file for this project, so Foundation classes are available to use”.

There is a couple of things I don’t understand about this.

It is correct that Foundation.h is in the precompiled header file, but so is UIKit.h, so why the need for including this in the BNRAppDelegate.h file?
Also, when doing the Foundation Command-Line programs, we still needed to include the Foundation.h file, even though it is also a part of that template’s precompiled header file?

Also, as far as I understand precompiled headers, all they do is they precompile the headers to cut down on compile time, so headers that aren’t changed very often and used all over the place are optimal candidates for inclusion in the precompiled header file - like Foundation.h and UIKit.h. But I have never heard that it means I didn’t need to include these header files.

By including UIKit.h I also indirectly include Foundation.h; e.g. by including UIKit.h I include UIButton.h which include Foundation.h. Isn’t that why I don’t need to include Foundation.h?


You could leave out the #import <UIKit/UIKit.h> and I think it should still compile. So the answer to your question “Why are they different?” is “They aren’t really.”


Ah, yes it does. So the reason to include UIKit.h is really a matter of “good taste”?

So whatever I put in the precompiled header is just available - didn’t know that.



Yes, it is just consider stylish to explicitly import your superclass’s header file.