Xcode 6 中的“嵌入式内容包含 Swift 代码”构建设置有什么作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24163870/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:03:38  来源:igfitidea点击:

What does the "Embedded Content Contains Swift Code" build setting in Xcode 6 do?

xcodeswiftxcode6ios-app-extension

提问by Johannes Fahrenkrug

It's a new setting under "Build Options". What does it do? I can't seem to find any documentation about it. My guess is this: Does it have to be set to YESin a mixed Objective-C/Swift app to tell Xcode to link against the Swift Runtime?

这是“构建选项”下的新设置。它有什么作用?我似乎找不到任何关于它的文档。我的猜测是:它是否必须YES在混合的 Objective-C/Swift 应用程序中设置为告诉 Xcode 链接到 Swift Runtime?

采纳答案by vladof81

It does not need to be Yesfor linking. This setting is only for when you have a pure Objective-C target that depends on a mixed-source or pure Swift target.

链接不需要是Yes。此设置仅适用于您拥有依赖于混合源或纯 Swift 目标的纯 Objective-C 目标时。

Description:

描述:

Enable this setting to indicate that content embedded in a target's product contains Swift code, so that the standard Swift libraries can be included in the product.

启用此设置以指示嵌入在目标产品中的内容包含 Swift 代码,以便标准 Swift 库可以包含在产品中。

Also in the release note of Beta 7:

同样在 Beta 7 的发行说明中:

The build step which embeds the Swift standard libraries in a bundle now only runs for application product types, and only if the application itself, independent of any embedded content, contains Swift source files. When building an application that itself does not contain Swift source files, but embeds other content like frameworks, XPC services, app extensions, etc. that do contain Swift code, you must set the build setting "Embedded Content Contains Swift Code" (EMBEDDED_CONTENT_CONTAINS_SWIFT). That way the Swift libraries will be included in the application.

将 Swift 标准库嵌入捆绑包中的构建步骤现在仅针对应用程序产品类型运行,并且仅当应用程序本身(独立于任何嵌入内容)包含 Swift 源文件时才运行。当构建本身不包含 Swift 源文件但嵌入其他内容(如框架、XPC 服务、应用程序扩展等)包含 Swift 代码的应用程序时,您必须设置构建设置“嵌入的内容包含 Swift 代码”(EMBEDDED_CONTENT_CONTAINS_SWIFT) . 这样 Swift 库将包含在应用程序中。

Regards

问候

回答by onmyway133

According to Embedding Content with Swift in Objective-C

根据在 Objective-C 中使用 Swift 嵌入内容

Swift standard libraries are copied into a bundle if and only if you are building an application and this application contains Swift source files by itself

If you are building an app that does not use Swift but embeds content such as a framework that does, Xcode will not include these libraries in your app. As a result, your app will crash upon launching

To workaround this issue, set the Embedded Content Contains Swift Code (EMBEDDED_CONTENT_CONTAINS_SWIFT) build setting to YES. This build setting, which specifies whether a target's product has embedded content with Swift code, tells Xcode to embed Swift standard libraries in your app when set to YES

当且仅当您正在构建一个应用程序并且该应用程序本身包含 Swift 源文件时,Swift 标准库才会被复制到一个包中

如果您正在构建一个不使用 Swift 但嵌入内容(例如使用 Swift 的框架)的应用程序,Xcode 将不会在您的应用程序中包含这些库。因此,您的应用程序将在启动时崩溃

要解决此问题,请将嵌入式内容包含 Swift 代码 (EMBEDDED_CONTENT_CONTAINS_SWIFT) 构建设置设置为 YES。此构建设置指定目标的产品是否已使用 Swift 代码嵌入内容,当设置为 YES 时,它会告诉 Xcode 在您的应用程序中嵌入 Swift 标准库

回答by Isaac Drachman

I don't believe that is required to have general interoperability between Swift and Objective-C. It's as simple as adding Swift code and editing the bridging header.

我认为 Swift 和 Objective-C 之间不需要通用互操作性。就像添加 Swift 代码和编辑桥接头一样简单。

If you see any of the documentation about Extensions for iOS, the lingo mentions "embedded" quite a bit: embedded content, embedded frameworks, etc. Because Extensions are organized, built, and run quite differently from normal apps, I wouldn't be surprised that there's a build setting like this one pertaining to them.

如果您看到有关 iOS 扩展的任何文档,该行话会多次提及“嵌入式”:嵌入式内容、嵌入式框架等。因为扩展的组织、构建和运行与普通应用程序完全不同,所以我不会很惊讶有这样的构建设置与他们有关。