对于使用Swift的目标,需要正确配置“Swift语言版本”(SWIFT_VERSION)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了对于使用Swift的目标,需要正确配置“Swift语言版本”(SWIFT_VERSION)相关的知识,希望对你有一定的参考价值。

我刚做了最后一次Xcode更新(8.3),我收到了消息:

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

知道刚刚从构建设置中删除了“使用Legacy Swift语言版本”选项,如何在不进行任何转换的情况下在Swift 2.3中生成我的应用程序?

答案

你不能。 XCode 8.2是支持Swift 2.3的最后一个版本。您必须更新到Swift 3或使用Xcode 8.2。

另一答案

在导航器选择栏中,单击放大镜,然后搜索“SWIFT_VERSION”您将在项目中找到可以相应调整swift版本的位置。

enter image description here

enter image description here

另一答案

要以编程方式更改pod的swift版本,您可以在Podfile中添加它

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if ['Alamofire','OtherPod','AnotherPod'].include? target.name
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '4.0'
            end
        end
    end
end

在Swift 4中,如果你也使用objective-c,

你可以打开@objc推理,这样swift项目就能在objective-c上正常运行。

post_install do |installer|
    installer.pods_project.targets.each do |target|
        if ['Alamofire','OtherPod','AnotherPod'].include? target.name
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_SWIFT3_OBJC_INFERENCE'] = 'On'
            end
        end
    end
end
另一答案

在我的情况下,我选择了Pod并更改了特定pod的swift版本。这适合我。

enter image description here

另一答案

你不能因为XCode 8.2是支持Swift 2.3的最后一个版本。您必须将代码更新为Swift 3或使用Xcode 8.2。

另一答案

该死的Xcode,现在我必须迁移到Swift 3.0。它在使用Swift 2.3打开或构建旧项目时清楚地显示此警报,因此我建议让我们迁移:( :(

enter image description here

另一答案

在构建设置中将Swift语言版本更改为支持的版本

enter image description here

另一答案

更新,它适合我:

第1步:转到您的ios文件夹并打开podfile并执行以下简单更改;

第一次改变:

target 'Runner' do
      use_frameworks! # <--- add this single line
      # Prepare symlinks folder. We use symlinks to avoid having Podfile.lock
      # referring to absolute paths on developers' machines.
      system('rm -rf .symlinks')
      system('mkdir -p .symlinks/plugins')

第二个变化:

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['ENABLE_BITCODE'] = 'NO'
      config.build_settings['SWIFT_VERSION'] = '3.2' # <--- add this single line
    end
  end
end

第2步:从Xcode打开您当前的工作项目,即转到ios文件夹并打开您的ProjectName.xcworkspace文件;

Add an empty Swift file to your Flutter iOS project in Xcode and accept to add bridging header.

步骤3:打开终端并使用以下命令再次安装;

pod install

如果项目已经打开,则关闭它并再次打开,即yourProjectName.xcworkspace文件,清理并构建。

以上是关于对于使用Swift的目标,需要正确配置“Swift语言版本”(SWIFT_VERSION)的主要内容,如果未能解决你的问题,请参考以下文章

对于使用 Swift 的目标,“Swift 语言版本”(SWIFT_VERSION)构建设置必须设置为受支持的值

Xcode 8.2使用旧版Swift问题[重复]

Xcode 8.3 不支持 Swift 2.3 [关闭]

如何在 Xcode8 上使用 Swift 2.2?

我编译 Swift 2.3 项目并在 Xcode 8.1 上有这个问题

IOS - Swift - 向 BarButtonItem 的 customView 添加目标和操作