How do I see which version of Swift I'm using?

后端 未结 15 1148
失恋的感觉
失恋的感觉 2020-11-28 17:20

I just created a new Swift project within Xcode. I am wondering which version of Swift it\'s using.

How can I see, in Xcode or the terminal, what version of Swift I

相关标签:
15条回答
  • 2020-11-28 17:54

    This reddit post helped me: https://www.reddit.com/r/swift/comments/4o8atc/xcode_8_which_swift/d4anpet

    Xcode 8 uses Swift 3.0 as default. But you can turn on Swift 2.3. Go to project's Build Settings and set 'Use Legacy Swift Language Version' to YES.

    Good old reddit :)

    0 讨论(0)
  • 2020-11-28 17:55

    From Xcode 8.3 onward Build Settings has key Swift Language Version with a value of swift version your target is using.

    For older Xcodes use this solution, open terminal and type following command(s)

    Case 1: You have installed only one Xcode App

    swift -version
    

    Case 2: You have installed multiple Xcode Apps

    • Switch active developer directory (Replace Xcode_7.3.app from following command with your Xcode app file name from Application directory for which you want to check swift version)

       sudo xcode-select --switch /Applications/Xcode_7.3.app/Contents/Developer
      
    • Then

       swift -version
      

    NOTE: From Xcode 8 to Xcode 8.2.x you can use swift 2.3 even though Xcode 8 uses swift 3.x as default swift version. To use swift 2.3, just turn on flag Use Legacy Swift Language Version to YES from Build Setting and XCode will use Swift 2.3 for that project target.

    0 讨论(0)
  • 2020-11-28 17:57

    I am using Swift from Google Colab. Here's how to check it in Colab.

    !/swift/toolchain/usr/bin/swift --version
    

    The result is 5.0-dev

    0 讨论(0)
  • 2020-11-28 17:59

    Updated answer for how to find which version of Swift your project is using in a few click in Xcode 12 to help out rookies like me.

    1. Click on your Project (top level Blue Icon in the left hand pane)
    2. Click on Build Settings (5th item in the Project > Header)
    3. Scroll down to Swift Compiler - Language, and look at the dropdown.

    0 讨论(0)
  • 2020-11-28 17:59

    You will get this under the project setting

    0 讨论(0)
  • 2020-11-28 18:00

    To see the default version of swift installed on your machine then from the command line, type the following :

    swift --version
    

    Apple Swift version 4.1.2 (swiftlang-902.0.54 clang-902.0.39.2)

    Target: x86_64-apple-darwin17.6.0

    This is most likely the version that is included in the app store version of Xcode that you have installed (unless you have changed it).

    If you want to determine the actual version of Swift being used by a particular version of Xcode (a beta, for instance) then from the command line, invoke the swift binary within the Xcode bundle and pass it the parameter --version

    /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
    

    Apple Swift version 4.2 (swiftlang-1000.0.16.7 clang-1000.10.25.3)

    Target: x86_64-apple-darwin17.6.0

    0 讨论(0)
提交回复
热议问题