Why import foundation.h?


In main, by default foundation.h is imported. But… in the part of this chapter about #include and #import, the following is stated:[quote]To make life easier and compiles faster, most Xcode projects have a file that lists headers to be precompiled in every file. In your Constants project, his file is called Constants-Prefix.pch[/quote]

When I look at this file, there’s the following code:[code]//
// Prefix header for all source files of the ‘Constants’ target in the ‘Constants’ project

#ifdef OBJC
#import <Foundation/Foundation.h>
Looks to me, Foundation.h is already included by default, when I remove the import from main, the code in my Constants project works just as nice. So I’m wondering… why is it imported at that place?!


You know, you don’t have to import Foundation.h anywhere but in that .pch file. But, we typically do. I think the compiler ignores it, so I don’t think it slows it down. To an old ObjC guy like me, it looks weird not to import the superclass at the start of the .h file.

I may just be old-fashioned, but I do the unnecessary imports.


Thanks for your speedy reply! I think I’ll leave the imports right where they are placed by default for now: after all, coders are lazy and taking it out is more work than leaving it in. :mrgreen:
If I have a project that’s so big that the compile time becomes an issue, I can always do a test to see if it compiles faster when I take them out.