ios 使用旧版 Swift 语言版本 - Xcode 8.2

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41118912/
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-08-31 10:55:21  来源:igfitidea点击:

Use Legacy Swift Language Version - Xcode 8.2

iosxcodeswift3xcode8.2

提问by Ale? Oskar Kocur

After updating to Xcode 8.2 the compiler throws one error for my App target:

更新到 Xcode 8.2 后,编译器会为我的 App 目标抛出一个错误:

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

需要为使用 Swift 的目标正确配置“使用旧版 Swift 语言版本”(SWIFT_VERSION)。使用 [Edit > Convert > To Current Swift Syntax…] 菜单选择 Swift 版本或使用 Build Settings 编辑器直接配置构建设置。

But have it set to Noin all targets I have. Tried to remove Derived Data, clean project dir, restart Xcode. Nothing helps. Anyone figure it out?

但是将它设置为No我拥有的所有目标。试图删除派生数据,清理项目目录,重新启动 Xcode。没有任何帮助。有谁想出来吗?

// Edited

// 编辑

Just to be sure: I have set to ALL my targets Use Legacy Swift Language Versionto Noand the project worked alright when compiled in Xcode 8.1. It doesn't work after updating to Xcode 8.2.

可以肯定的是:我已将所有目标设置为Use Legacy Swift Language VersionNo并且该项目在 Xcode 8.1 中编译时运行良好。更新到 Xcode 8.2 后它不起作用。

// Edit 21.12.

// 编辑 21.12。

The issue has been fixed in Xcode 8.2.1

该问题已在 Xcode 8.2.1 中修复

回答by zumzum

Found work around. I went through each target (and project settings, so both in the project and target) in my project, toggledthe "Use Legacy Swift Language Version" from "No" to "Yes" and back to "No" for each. The project then built again.

找到了解决办法。我浏览了我的项目中的每个目标(和项目设置,因此在项目和目标中),将“使用旧版 Swift 语言版本”从“”切换到“”,然后为每个切换回“”。然后该项目再次构建。

enter image description here

在此处输入图片说明

回答by Aklesh Rathaur

I got the same error. I tried for searching "Use Legacy Swift Language Version", but not found. I am using Xcode 8.3.3After surfing too much and working around i found this solution, and this worked for me.

我得到了同样的错误。我尝试搜索“使用旧版 Swift 语言版本”,但没有找到。我正在使用 Xcode 8.3.3在冲浪太多并解决之后我找到了这个解决方案,这对我有用。

Follow these steps.
1=> select your target from Xcode
2=> go to build setting
3=> search for "Swift Language Version"
4=> change it to swift 3. (or accordingly.)

Hope this work for you.

希望这对你有用。

回答by C?ur

Fixed in Xcode 8.2.1.

在 Xcode 8.2.1 中修复。

Here is a copy of the integrality of the changelog of Xcode 8.2.1:

这是Xcode 8.2.1 更新日志完整性的副本:

Swift

Resolved Issues

  • Fixed an issue that could cause building a project to fail with the error message “"Use Legacy Swift Language Version" (SWIFT_VERSION) is required to be configured correctly for targets which use Swift” when using a supported version of Swift. (29667880)
  • Xcode no longer warns about using deprecated Swift 2.3 code when the active scheme does not reference targets using Swift 2.3 code. (29671741)

迅速

已解决的问题

  • 修复了在使用受支持的 Swift 版本时可能导致构建项目失败并显示错误消息“需要为使用 Swift 的目标正确配置“使用旧版 Swift 语言版本”(SWIFT_VERSION)”的问题。(29667880)
  • 当活动方案未引用使用 Swift 2.3 代码的目标时,Xcode 不再警告使用已弃用的 Swift 2.3 代码。(29671741)

回答by dianakarenms

This is the only thing that worked for me...

这是唯一对我有用的东西......

For errors with pods. Basically we need to enable “Legacy Swift Language”. Select your pod framework (by clicking on it in the error navigator) and under Build Settings find “Use Legacy Swift Language Version”

对于 pod 的错误。基本上我们需要启用“Legacy Swift Language”。选择您的 pod 框架(通过在错误导航器中单击它)并在 Build Settings 下找到“Use Legacy Swift Language Version”

enter image description here

在此处输入图片说明

Set it to “Yes”. Then “Build & Run” again to test it.

将其设置为“是”。然后再次“构建并运行”来测试它。

Check out this post: http://rebeloper.com/downgrade-swift-3-swift-2-3-xcode-8/

看看这篇文章:http: //rebeloper.com/downgrade-swift-3-swift-2-3-xcode-8/

回答by Klaas

Close Xcode and open the corresponding project.pbxprojin a text editor of your choice.

关闭 Xcode 并project.pbxproj在您选择的文本编辑器中打开相应的。

Replace SWIFT_VERSION = 3.0.1;with SWIFT_VERSION = 3.0;for all targets.

更换SWIFT_VERSION = 3.0.1;SWIFT_VERSION = 3.0;的所有目标。

Reopen Xcode.

重新打开 Xcode。

回答by Ale? Oskar Kocur

Well I've finally figure it out. I've removed the project and clone it again, restarted Xcode, run pod repo updateand pod installand it worked. I've no idea why.

嗯,我终于弄明白了。我再次取出该项目,并克隆它,重新启动的Xcode,运行pod repo update以及pod install和它的工作。我不知道为什么。

回答by ScottyB

I got the same error when converting parts of my app (both Obj C and Swift) to a framework, but in my case it was that the "Swift Language Version" under Build Settings wasn't set. I set it to Swift 3 (the only option), and the error went away.

将我的应用程序的一部分(Obj C 和 Swift)转换为框架时,我遇到了同样的错误,但在我的情况下,是未设置“构建设置”下的“Swift 语言版本”。我将它设置为 Swift 3(唯一的选项),错误就消失了。

回答by Laser Hawk

This did not work for us :( reverting back to Xcode 8.1 is best for now until Apple QA's their stuff before they release.

这对我们不起作用:(目前最好恢复到 Xcode 8.1,直到 Apple QA 在他们发布之前提供他们的东西。

If its any consolation here are things we tried and got us very close. We got stuck at the Clean Failed:

如果这有什么安慰的话,那就是我们尝试过并且让我们非常接近的事情。我们陷入了 Clean Failed:

rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache

rm -rf ~/Library/Developer/Xcode/DerivedData/ModuleCache

rm -rf ~/Library/Preferences/com.apple.Xcode.plist

rm -rf ~/Library/Preferences/com.apple.Xcode.plist

restart Xcodeand do a deep clean holding the optionkey

重新启动Xcode并按住option钥匙进行深度清洁

That got rid of the Clean Failed.

这摆脱了 Clean Failed。

Adding this to your pod script

将此添加到您的 pod 脚本中

post_install do |installer|

post_install do |installer|

installer.pods_project.targets.each do |target|

installer.pods_project.targets.each do |target|

target.build_configurations.each do |config|

target.build_configurations.each do |config|

config.build_settings['SWIFT_VERSION'] = '3.0'

config.build_settings['SWIFT_VERSION'] = '3.0'

end

end

end

end

end

end

That is the way to have all pods conform to 3.0 and we actually got it to build, but at the end of compiling we got this error:

这就是让所有 Pod 符合 3.0 的方法,我们实际上已经构建了它,但是在编译结束时我们得到了这个错误:

“Use Legacy Swift Language Version” (SWIFT_VERSION) is required to be configured correctly for targets which use Swift. Use the [Edit > Convert > To Current Swift Syntax…] menu to choose a Swift version or use the Build Settings editor to configure the build setting directly.

How do we change the workspace so that all projects conform to swift 3.0? Where is that setting?

我们如何更改工作区,以便所有项目都符合 swift 3.0?那个设定在哪里?

回答by Laser Hawk

It turns out that Apple decided to reference a version of the swift language that doesn't exist yet within the pbxprojec file. They hard coded 3.0.1, and by manually editing the sudo XML in the pbx file back to 3.0 everything worked again. Apple apparently overlooked some simple QA work before they released 8.2

事实证明,Apple 决定引用 pbxprojec 文件中尚不存在的 swift 语言版本。他们对 3.0.1 进行了硬编码,并通过手动将 pbx 文件中的 sudo XML 编辑回 3.0,一切又恢复正常。苹果在发布 8.2 之前显然忽略了一些简单的 QA 工作

This could also explain why toggling between legacy in the build settings worked for some people.

这也可以解释为什么在构建设置中的传统之间切换对某些人有效。