Swift项目中的链接框架和库 [英] Linked frameworks and libraries in Swift project
问题描述
我的iOS应用以 AVPlayer
播放声音。要做到这一点,我必须在类的顶部键入以下内容:
My iOS app plays sounds with AVPlayer
. To do this I had to type following on the top of a class:
import AVFoundation
我来自Objective-C背景,所以我去了Xcode项目的 General 标签并添加了 AVFoundation
点击链接框架和库下的加号按钮。黄色工具箱出现在我的项目中。我是否必须这样做?
I came from Objective-C background, so I went to Xcode project's General tab and added AVFoundation
there by clicking on plus button under the Linked frameworks and libraries. Yellow toolbox appeared in my project. Do I have to do this?
我试图将它从项目中移除 - 无论是从侧边栏还是在Xcode偏好设置中,我的应用程序仍然可以正常播放。那么 import
为你处理一切吗?
I tried to remove it from the project — both from the sidebar and in Xcode preferences, my app still works and sounds are playing. So does import
handling everything for you?
推荐答案
是的,<$ Swift中的c $ c> import 与Objective-C中的 @import
基本相同(而不是 #import < ...>
),导入模块。
Yes, import
in Swift is basically the same as @import
in Objective-C (as opposed to #import <…>
), which import modules.
最近推出了这个新功能(模块)( 1 - 2年前?)和确实为您导入框架而无需将应用程序与其明确链接:使用模块时( @import
在ObjC中,导入
在Swift中),编译器将看到模块名称,并为您隐式和自动地链接您的应用程序框架。
This new feature (modules) was introduced recently (1-2 years ago?) and does import the framework for you without the need to explicitly link you app with it: when using modules (@import
in ObjC, import
in Swift), the compiler will see the module name and link your app with the framework implicitly and automagically for you.
这是我们在 #import
是唯一选项时我们没有回来的新功能,我们必须自己手动添加系统框架。
So that's a new feature we didn't have back in the day when #import
were the only option and we had to manually add system frameworks ourselves.
(请注意,模块仅适用于Apple的框架,直到iOS8到货。但现在您可以构建您的o了在为iOS8构建动态框架时,它们也可用于第三方框架,只要它们具有 module.map
)
如果您有兴趣,可以阅读更多在Clang文档本身。各种博客文章也谈论这个主题(例如,首先谷歌的结果是这篇博文)
If you're interested, you can read more in the Clang documentation itself. Various blog posts also talk about the subject (e.g. first Google result is this blog post)
这篇关于Swift项目中的链接框架和库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!