框架的“导入”和框架的“链接”有什么区别?

时间:2022-02-04 19:02:56

I'm new in Xcode and in Swift language. I'm trying to understand the usage of the "import" in ViewController and the "framework import" in my project. Example: if I use CoreLocation, need I only import CoreLocation in my ViewController, or I need to import CoreLocation.framework in my project too? I saying this because everything works well only using import CoreLocation at the top of my ViewController, without import its framework.

我是Xcode和Swift语言的新手。我试图了解ViewController中“import”的用法以及我项目中的“框架导入”。示例:如果我使用CoreLocation,我只需要在ViewController中导入CoreLocation,还是需要在项目中导入CoreLocation.framework?我这样说是因为一切都运行良好,只使用我的ViewController顶部的导入CoreLocation,而不导入它的框架。

Thanks!

1 个解决方案

#1


7  

The import in the source code facilitates compilation of your code, ensuring that the correct headers are found. The "Link Binary with Libraries" section of the "Build Phases" in "Project Settings" (now also included on the "Summary" tab under "Linked Libraries and Frameworks") specifies with which frameworks and libraries your object code will be linked.

源代码中的导入有助于编译代码,确保找到正确的标头。 “项目设置”中“构建阶段”的“链接二进制文件”部分(现在也包含在“链接库和框架”下的“摘要”选项卡中)指定了目标代码将链接到哪些框架和库。

Historically we always needed to specify these two separately, but now there is a project setting "Link Frameworks Automatically", which if on, will automatically link the framework to your project if you import it in your source code. You also must have "Enable Modules" turned on, too.

从历史上看,我们总是需要单独指定这两个,但现在有一个项目设置“自动链接框架”,如果启用,将自动将框架链接到您的项目,如果您在源代码中导入它。您也必须打开“启用模块”。

#1


7  

The import in the source code facilitates compilation of your code, ensuring that the correct headers are found. The "Link Binary with Libraries" section of the "Build Phases" in "Project Settings" (now also included on the "Summary" tab under "Linked Libraries and Frameworks") specifies with which frameworks and libraries your object code will be linked.

源代码中的导入有助于编译代码,确保找到正确的标头。 “项目设置”中“构建阶段”的“链接二进制文件”部分(现在也包含在“链接库和框架”下的“摘要”选项卡中)指定了目标代码将链接到哪些框架和库。

Historically we always needed to specify these two separately, but now there is a project setting "Link Frameworks Automatically", which if on, will automatically link the framework to your project if you import it in your source code. You also must have "Enable Modules" turned on, too.

从历史上看,我们总是需要单独指定这两个,但现在有一个项目设置“自动链接框架”,如果启用,将自动将框架链接到您的项目,如果您在源代码中导入它。您也必须打开“启用模块”。