如何修复 Xcode 10.2 中的“SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0”错误?

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

How to fix "SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0" error in Xcode 10.2?

xcodeswift3xcode10.2

提问by vlad uvarov

I'm trying to run downloaded from app, try to open in Xcode and have an error:

我正在尝试从应用程序下载运行,尝试在 Xcode 中打开并出现错误:

" Showing Recent Messages
:-1: SWIFT_VERSION '3.0' is unsupported, supported versions are: 4.0, 4.2, 5.0. (in target 'SimpleWeather')"

“显示最近的消息
:-1:不支持 SWIFT_VERSION '3.0',支持的版本是:4.0、4.2、5.0。(在目标 'SimpleWeather' 中)”

Screenshot added

添加了截图

回答by Xeneka

Select the target 'SimpleWeather' in the project and change language version Target->build setting -> Swift compiler language -> select 5, 4.2 etc

在项目中选择目标“SimpleWeather”并更改语言版本 Target->build setting -> Swift compiler language -> select 5, 4.2 etc

image of build setting for changing compiler language

用于更改编译器语言的构建设置的图像

回答by Kingsley Mitchell

******** Easiest way: **********

******** 最简单的方法:**********

1.Click on PODs in the left column.

1. 单击左栏中的 POD。

2.In the centre column select the pod you want, then navigate to "build settings" in the top right panel.

2.在中间列中选择您想要的 pod,然后导航到右上角面板中的“构建设置”。

3.Then search "Swift Language Version" and change to a known version.

3.然后搜索“Swift Language Version”并更改为已知版本。

enter image description hereenter image description here

在此处输入图片说明在此处输入图片说明

回答by Deepak Chaudhary

For Xcode 10.1, select your Pods File

对于 Xcode 10.1,选择您的 Pods 文件

enter image description here

在此处输入图片说明

-> Go to Build Settings -> Choose your Pod -> Search "Swift" -> Navigate to "Swift Language version" -> Set to desired language version.

-> 转到构建设置 -> 选择您的 Pod -> 搜索“Swift” -> 导航到“Swift 语言版本”-> 设置为所需的语言版本。

enter image description here

在此处输入图片说明

回答by Forrest

I followed the instructions on this page and the error didn't resolve. Finally, went into

我按照此页面上的说明操作,但错误没有解决。最后,进入

$ vim MyProject.xcodeproj/project.pbxproj

and found two instances where

并发现了两个实例,其中

SWIFT_VERSION = 3.0;

was still being referenced. I changed those to 5.0 and the error was gone. Not sure why those two were still there.

仍然被引用。我将它们更改为 5.0,错误消失了。不知道为什么那两个人还在那里。

回答by Govind Wadhwa

enter image description hereselect pod like as per image and change swift language version this can save you one day

在此处输入图片说明选择像每张图片一样的 pod 并更改 swift 语言版本,这可以为您节省一天

enter image description here

在此处输入图片说明

回答by Manoj Rawat

  1. Select project
  2. Select Build SettingTab
  3. Select Swift Compiler language Option
  1. 选择项目
  2. 选择构建设置选项卡
  3. 选择 Swift 编译器语言选项

enter image description here

在此处输入图片说明

回答by Bhavin_m

It seems that the app might have an old Swift version code like Swift 3.0 in your case. In the release of Xcode version 10.2 has launched Swift 5.0 version. Xcode 10.2 does not support compiler for Swift 3.0 version. You can change compiler from Build Settings -> Swift Compiler - Language -> Swift Language Version -> Change it to Swift 5. If your code is compatible with that language version then it will run the code without error.

在您的情况下,该应用程序似乎具有旧的 Swift 版本代码,例如 Swift 3.0。在发布 Xcode 10.2 版本时又推出了 Swift 5.0 版本。Xcode 10.2 不支持 Swift 3.0 版本的编译器。您可以从Build Settings -> Swift Compiler - Language -> Swift Language Version -> Change it to Swift 5. 如果您的代码与该语言版本兼容,那么它将运行代码而不会出错。

However, the Swift 3 compatibility mode will not be supported in the Swift 5 compiler. Swift 4.2 is the last release of Swift to support Swift 3 mode. There are important changes to both the surface of the language and the interior of its implementation in the releases following Swift 3 that will be the basis of future (and lasting) source and binary stability.

但是,Swift 5 编译器将不支持 Swift 3 兼容模式。Swift 4.2 是最后一个支持 Swift 3 模式的 Swift 版本。在 Swift 3 之后的版本中,语言的表面和内部实现都有重要的变化,这将成为未来(和持久)源代码和二进制稳定性的基础。

Refer below link for more details. https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes/swift_5_release_notes_for_xcode_10_2

请参阅以下链接了解更多详情。 https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_release_notes/swift_5_release_notes_for_xcode_10_2

If you really wish to run the app which has older Swift version code than you must have to use an older version of Xcode. You can use Xcode version 10.1, it's compiler having support for Swift 3.0 version.

如果您真的希望运行具有较旧 Swift 版本代码的应用程序,则必须使用较旧版本的 Xcode。您可以使用 Xcode 10.1 版,它的编译器支持 Swift 3.0 版。

Another alternative way is to migrate your old Swift code to the new version of the Swift version. You can migrate you Swift 3.0 to Swift 4.0 in Xcode 10.1 version.

另一种替代方法是将旧的 Swift 代码迁移到 Swift 版本的新版本。您可以在 Xcode 10.1 版本中将 Swift 3.0 迁移到 Swift 4.0。

For migration guide refer to this https://swift.org/migration-guide-swift4/

有关迁移指南,请参阅此 https://swift.org/migration-guide-swift4/

回答by Justin Vallely

I came across this issue while developing a Cocoapod. I had an old .swift-versionfile in my repo that specified Swift 3.0.

我在开发 Cocoapod 时遇到了这个问题。我的.swift-version仓库中有一个旧文件,指定了 Swift 3.0。

Running pod lib lint --verboseled me to this helpful response:

跑步pod lib lint --verbose让我得到了这个有用的回应:

Please remove the .swift-versionfile which is now deprecated and only use the swift_versionattribute within your podspec.

请删除.swift-version现在已弃用的文件,并仅swift_version在您的 podspec 中使用该属性。

I deleted the file and added spec.swift_version = '5.0'to my podspec file to fix the problem.

我删除了该文件并添加spec.swift_version = '5.0'到我的 podspec 文件中以解决该问题。

回答by coders

  1. Check this out:
    1. Click on Project name
    2. Click target
    3. Click on Build setting
    4. At the Swift Language Version: Choose Swift 4
  1. 看一下这个:
    1. 点击项目名称
    2. 点击目标
    3. 点击构建设置
    4. 在 Swift 语言版本:选择 Swift 4

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

回答by Dan Alboteanu

I opened up the file MyProject.xcodeproj(using VSCode editor)

我打开了文件MyProject.xcodeproj(使用 VSCode 编辑器)

and I found some lines where

我发现了一些行

SWIFT_VERSION = 3.0;

SWIFT_VERSION = 3.0;

(at about line 400 where it says /* Begin XCBuildConfiguration section */)

(大约在它说的第 400 行/* Begin XCBuildConfiguration section */

Modify to SWIFT_VERSION = 5.0 or others. After that I was able build and run the project.

修改为 SWIFT_VERSION = 5.0 或其他。之后,我能够构建和运行该项目。