为什么一个简单的程序导入<Foundation/Foundation.h>而不是单独的头文件? [英] Why does a simple program import &lt;Foundation/Foundation.h&gt; instead of individual header files?

查看:237
本文介绍了为什么一个简单的程序导入<Foundation/Foundation.h>而不是单独的头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Objective-C 的新手.Xcode 生成的模板代码包含:

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

#import <Foundation/Foundation.h>

当我在/System/Library/Frameworks/Foundation.framework/Headers 查看时,有将近 2000 个头文件!

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

我的问题是,对于只使用 NSString 的非常简单的代码,为什么不只导入 NSString.h 文件?

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

导入一大堆Foundation框架会影响可执行文件的性能吗?如果没有,它有什么好处吗?

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

推荐答案

它不会影响性能,因为内置框架都安装在您的设备上,已经准备好由您的可执行文件链接.

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.

当您#import 时,您所说的是即使我不使用Foundation 框架的所有功能,我也想访问它".它是一个语义划分.

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.

仅仅在 NSString.h 上做一个导入的问题是你知道 NSString 有什么依赖关系.我不知道,也不需要.

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.

这篇关于为什么一个简单的程序导入<Foundation/Foundation.h>而不是单独的头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆