Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does a simple program import <Foundation/Foundation.h> instead of individual header files?

Tags:

objective-c

I'm new to Objective-C. The Xcode generated template code contains:

#import <Foundation/Foundation.h>

When I check it at /System/Library/Frameworks/Foundation.framework/Headers, there are nearly 2 thousands header files!

My question is, for a really simple code that use only NSString, why not import just the NSString.h file?

Does importing the whole bunch of Foundation framework affect the performance of executables? If not, does it have some benefits?

like image 492
Stephen Hsu Avatar asked Aug 15 '10 12:08

Stephen Hsu


1 Answers

It doesnt affect the performance as the inbuilt frameworks are all there installed on your device already ready to be linked to by your executable.

What you are saying when you #import <Foundation/Foundation.h> is "I would like access to the functionality of the Foundation framework even if I don't use it all". Its a semantic division.

The compiler will do all the optimisation that needs doing with respect to discarding unused symbols.

The problem with just doing an import on NSString.h is do you know what dependencies there are for NSString. I don't know, and dont need to either.

like image 194
Warren Burton Avatar answered Sep 18 '22 21:09

Warren Burton