本文翻译自: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
(ReplaceXcode_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 Setting
为YES
,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中可用(尚未检查较旧的版本)