如何查看我正在使用哪個版本的Swift?

本文翻譯自:How do I see which version of Swift I'm using?

I just created a new Swift project within Xcode. 我剛剛在Xcode中創建了一個新的Swift項目。 I am wondering which version of Swift it's using. 我想知道它正在使用哪個版本的Swift。

How can I see, in Xcode or the terminal, what version of Swift I am using inside my project? 如何在Xcode或終端中查看我在項目中使用的Swift的哪個版本?


#1樓

參考:https://stackoom.com/question/25Bvw/如何查看我正在使用哪個版本的Swift


#2樓

What I do is say in the Terminal: 我在終端中說的是:

$ xcrun swift -version

Output for Xcode 6.3.2 is: Xcode 6.3.2的輸出是:

Apple Swift version 1.2 (swiftlang-602.0.53.1 clang-602.0.53)

Of course that assumes that your xcrun is pointing at your copy of Xcode correctly. 當然,這假定您的xcrun正確指向了您的Xcode副本。 If, like me, you're juggling several versions of Xcode, that can be a worry! 如果像我一樣,您在使用Xcode的多個版本,那可能會令人擔憂! To make sure that it is, say 爲了確定它,說

$ xcrun --find swift

and look at the path to Xcode that it shows you. 並查看顯示給您的Xcode的路徑。 For example: 例如:

/Applications/Xcode.app/...

If that's your Xcode, then the output from -version is accurate. 如果那是您的Xcode,那麼-version的輸出是準確的。 If you need to repoint xcrun , use the Command Line Tools pop-up menu in Xcode's Locations preference pane. 如果需要重新指向xcrun ,請使用Xcode的“位置”首選項窗格中的“命令行工具”彈出菜單。


#3樓

打開終端並輸入:

swift -version

#4樓

From Xcode 8.3 onward Build Settings has key Swift Language Version with a value of swift version your target is using. 從Xcode 8.3開始,“ Build Settings具有關鍵的“ Swift Language Version和目標所使用的swift版本值。

For older Xcodes use this solution, open terminal and type following command(s) 對於較舊的Xcode,請使用此解決方案,打開終端並鍵入以下命令

Case 1: You have installed only one Xcode App 情況1:您僅安裝了一個Xcode應用程序

swift -version

Case 2: You have installed multiple Xcode Apps 情況2:您已經安裝了多個Xcode應用程序

  • 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) 切換active developer directory (用您要檢查快速版本的應用程序目錄中的Xcode應用程序文件名替換以下命令中的Xcode_7.3.app

      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. 注意:從Xcode 8到Xcode 8.2.x,即使Xcode 8使用swift 3.x作爲默認的swift版本,您也可以使用swift 2.3。 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. 要使用swift 2.3,只需將Build Setting Use Legacy Swift Language Version標記Build SettingYES ,XCode將對該項目目標使用Swift 2.3。


#5樓

This reddit post helped me: https://www.reddit.com/r/swift/comments/4o8atc/xcode_8_which_swift/d4anpet 這篇reddit帖子對我有所幫助: https : //www.reddit.com/r/swift/comments/4o8atc/xcode_8_which_swift/d4anpet

Xcode 8 uses Swift 3.0 as default. Xcode 8默認使用Swift 3.0。 But you can turn on Swift 2.3. 但是您可以打開Swift 2.3。 Go to project's Build Settings and set 'Use Legacy Swift Language Version' to YES. 轉到項目的“構建設置”,並將“使用舊版Swift語言版本”設置爲“是”。

Good old reddit :) 好老reddit :)


#6樓

You can see and select which Swift version Xcode is using in: 您可以查看並選擇Xcode在以下版本中使用的Swift版本:

Target -> Build Settings -> Swift Language Version : 目標 -> 構建設置 -> Swift語言版本

在此處輸入圖片說明

This is available in Xcode 8.3 and Xcode 9 (haven't checked older versions) 在Xcode 8.3和Xcode 9中可用(尚未檢查較舊的版本)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章