While learning iPhone programming, every Xcode template I've seen includes an AppName-Prefix.pch file with the following contents:
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#endif
My understanding is that this file's contents are prefixed to each of the source code files before compilation. Yet each of the other files also imports UIKit, which seems superfluous. For example, main.m
begins...
#import <UIKit/UIKit.h>
int main(int argc, char *argv[]) {
...
Cocoa applications in Mac OS X do the same thing, importing Cocoa.h in both the prefix file and the header files.
Why have both? I removed the #import
directives from all of the source files except the prefix file, and it compiled and ran correctly.