Which header files to import?


I noticed on this chapter on p231, location 5510, kindle, that ImageStore.h should import UIKit.h, but not Foundation.h

Yet, when I create the subclass files, Xcode 4.2 already inserts the code to import Foundation.h, but not UIKit.h.

So, which is it? Does this class not need Foundation.h as per the book?

When searching for the answer, I found that every project has a prefix.pch file, which includes Foundation.h and UIKit.h for all files already. So I guess my question “assumes” that we don’t have this file.
From the documentation, I gathered that UIKit.h deals with User Interface stuff, while Foundation.h handles objective c, deallocs, etc.

So I guess we need both, right?


UIKit.h will import Foundation.h.

Because the template do fun things depending on the Xcode version (like change which files are imported for each template), we decided not to worry about it because the pch file will always import UIKit and Foundation.

However, yes, if you have a file that uses a UIKit class, it needs to import UIKit. You can always import UIKIt and get Foundation for free. The only time this will be an issue is if you are using the same file on Mac OS X, where UIKit doesn’t exist.