怎么检查,游戏的swift版本?

时间:2022-06-01 14:03:36

I was just testing my code in play ground(xcode-8.2), using swift tutorial. I came across following sample code:

我只是使用swift教程在play ground(xcode-8.2)中测试我的代码。我遇到了以下示例代码:

One-Sided Ranges

for name in names[2...] {
    print(name)
}

now my play ground showing an error:

现在我的游戏场显示错误:

怎么检查,游戏的swift版本?

now I feel that my swift version may not be supporting this code!

现在我觉得我的swift版本可能不支持这段代码!

I looked around this answer but it provide solution for Xcode Project only.

我查看了这个答案,但它只为Xcode Project提供了解决方案。

How can I see swift version of play ground?

我怎么能看到快速版的游戏场?

3 个解决方案

#1


3  

Try to find out swift version using following code. (Here I tried this code with Playground of Xcode 9.3 - beta 4) and it's providing me correct answer.

尝试使用以下代码找出swift版本。 (这里我用Xcode 9.3-beta 4的Playground尝试了这个代码),它为我提供了正确的答案。

#if swift(>=5.0)
print("Hello, Swift 5.0")
#elseif swift(>=4.1)
print("Hello, Swift 4.1")
#elseif swift(>=4.0)
print("Hello, Swift 4.0")
#elseif swift(>=3.0)
print("Hello, Swift 3.x")
#else
print("Hello, Swift 2.2")
#endif

怎么检查,游戏的swift版本?

Answer to your question: I'm not sure but according to result of above code, I can say, Latest Swift version supported by your Xcode tool becomes a version of Playground's Swift Language.

回答你的问题:我不确定,但根据上述代码的结果,我可以说,你的Xcode工具支持的最新Swift版本成为Playground的Swift语言版本。

#2


0  

In the terminal run

在终端运行中

swift -version

in all probability playgrounds will be using that version

所有概率游乐场都将使用该版本

#3


0  

By default Playground use the Swift version based on your Xcode version

默认情况下,Playground使用基于Xcode版本的Swift版本

You can check the Swift version by Xcode release here https://swift.org/download/#releases

你可以在这里查看Xcode发布的Swift版本https://swift.org/download/#releases

#1


3  

Try to find out swift version using following code. (Here I tried this code with Playground of Xcode 9.3 - beta 4) and it's providing me correct answer.

尝试使用以下代码找出swift版本。 (这里我用Xcode 9.3-beta 4的Playground尝试了这个代码),它为我提供了正确的答案。

#if swift(>=5.0)
print("Hello, Swift 5.0")
#elseif swift(>=4.1)
print("Hello, Swift 4.1")
#elseif swift(>=4.0)
print("Hello, Swift 4.0")
#elseif swift(>=3.0)
print("Hello, Swift 3.x")
#else
print("Hello, Swift 2.2")
#endif

怎么检查,游戏的swift版本?

Answer to your question: I'm not sure but according to result of above code, I can say, Latest Swift version supported by your Xcode tool becomes a version of Playground's Swift Language.

回答你的问题:我不确定,但根据上述代码的结果,我可以说,你的Xcode工具支持的最新Swift版本成为Playground的Swift语言版本。

#2


0  

In the terminal run

在终端运行中

swift -version

in all probability playgrounds will be using that version

所有概率游乐场都将使用该版本

#3


0  

By default Playground use the Swift version based on your Xcode version

默认情况下,Playground使用基于Xcode版本的Swift版本

You can check the Swift version by Xcode release here https://swift.org/download/#releases

你可以在这里查看Xcode发布的Swift版本https://swift.org/download/#releases