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

跟風遠走 提交于 2019-11-27 22:56:13

问题


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 YES in a mixed Objective-C/Swift app to tell Xcode to link against the Swift Runtime?


回答1:


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

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.

Also in the release note of 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.

Regards




回答2:


According to Embedding Content with Swift in Objective-C

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




回答3:


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.

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.



来源:https://stackoverflow.com/questions/24163870/what-does-the-embedded-content-contains-swift-code-build-setting-in-xcode-6-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!