Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Foundation.h not imported in the standard Xcode templates?

I just noticed that when I create iPhone application using standard templates in Xcode (View Based Application, Window based application etc) the header files only import UIKit.h (and not Foundation.h). So if the Foundation.h file is not imported, how can one use Foundation classes like NSString, NSArray etc in the program ? Shouldn't it be throwing an error?

like image 889
NSExplorer Avatar asked Dec 16 '22 13:12

NSExplorer


1 Answers

It is imported in the precompiled header file (extension .pch) in your project.

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
#endif

As to why UIKit.h appears to have two import lines per file since it also shows up above, though, I'm not too sure. It shouldn't matter anyway, as the second #import line won't cause UIKit to be included again if it's already included in the precompiled header file.

like image 51
BoltClock Avatar answered Jan 17 '23 16:01

BoltClock