Rob
Rob

Reputation: 4224

Cocoapods: how to create a pod using the latest Swift version?

I am learning how to create a pod using Cocoapods, so I ran this command:

pod lib create {my_pod_name}

Using iOS platform, Swift language, including a demo application in my library, and not using any testing framework nor view based testing.

However, when opening the project, I'm getting the warning:

Conversion to Swift 4.2 is available

That's what I see in the build settings:

enter image description here

So why is this happening?

Thanks for your help!

Upvotes: 4

Views: 2638

Answers (1)

Adis
Adis

Reputation: 4552

If I understood your question correctly, the Swift version is dictated by the Podspec.

In more details, it would look like:

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

I assume that if this is left out, that it currently defaults to 4.0.

If you want to go more into detail, check the 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

Upvotes: 4

Related Questions