Swift: What is a .swift-version file? Swift: What is a .swift-version file? swift swift

Swift: What is a .swift-version file?


This seems quite similar to the practice of a .ruby-version file which instructs a version manager like rvm to pick up a particular version of ruby. But what it's doing in case of swift, I am not really sure. Here are two related scenarios that I have come across:

  1. It seems that this flag is used by the cocoapods to set some target level settings on pods. Refer:

Cocoapods issue

This cocoapod pull request can also provide some clue

  1. Another place I have come across it is swiftenv. This is quit like rvm (or say nvm) which can help you manage multiple versions of swift.

This is not an exact answer. But I hope it provides some information.


In the examples you provided the .swift-version file is using by CocoaPods, but since CocoaPods 1.4.0 you should not maintain this file anymore. Use the swift_version attribute to specify the Swift version instead. Check this example of a .podspec file for CocoaPods 1.6.0.beta.2:

Pod::Spec.new do |s|  #other attributes  s.swift_version = '4.2'end

Here you can find more details about CocoaPods 1.4.0 release. Check the section Swift Version DSL.

More than that, since CocoaPods 1.7.0.beta.1 you will get a warning if you try to use .swift-version file, see this link for more details.


It looks like this is a way to mark Pods as Swift and indicate the version to use. It also seems it will trigger the CocoaDocs generation in Swift (once CocoaDocs supports that).

See the CocoaPods CHANGELOG file.