Cocoapods:如何使用最新的Swift版本创建Pod?

时间:2019-03-01 17:09:03

标签: ios cocoapods

我正在学习如何使用Cocoapods创建吊舱,所以我运行了以下命令:

pod lib create {my_pod_name}

使用iOS平台的Swift语言,包括我库中的演示应用程序,而不使用任何测试框架或基于视图的测试。

但是,当打开项目时,我得到警告:

  

可以转换为Swift 4.2

这就是我在构建设置中看到的:

enter image description here

那为什么会这样呢?

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

如果我正确理解了您的问题,则Podspec决定了Swift版本。

详细信息如下:

Pod::Spec.new do |spec|
  ...
  spec.swift_version = '4.2'
  ...
end

我认为,如果忽略此选项,则当前默认为4.0。

如果要详细介绍,请检查source

# @return [String] the Swift version for the target. If the pod author has provided a set of Swift versions
#         supported by their pod then the max Swift version across all of target definitions is chosen, unless
#         a target definition specifies explicit requirements for supported Swift versions. Otherwise the Swift
#         version is derived by the target definitions that integrate this pod as long as they are the same.
#
def swift_version
  @swift_version ||= begin
    if spec_swift_versions.empty?
      target_definitions.map(&:swift_version).compact.uniq.first
    else
      spec_swift_versions.sort.reverse_each.find do |swift_version|
        target_definitions.all? do |td|
          td.supports_swift_version?(swift_version)
        end
      end.to_s
    end
  end
end