How to check the fast version for the playground?

I just tested my code on the playground (xcode-8.2) using a quick tutorial. I came across the following code example:

One-way ranges

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

now my playground shows an error:

enter image description here

Now I feel that my fast version may not support this code!

I looked at this answer, but it offers a solution only for the Xcode project.

How can I see the fast version of the playing field?

+4
source share
3 answers

In terminal run

swift -version

most likely playgrounds will use this version

0
source

By default, Playground uses a version of Swift based on your version of Xcode.

Swift Xcode https://swift.org/download/#releases

0

Try to find the fast version using the following code. (Here I tried this code with the Xcode 9.3 - beta 4 playground ) and this gives me the correct answer.

#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

enter image description here

Answer your question: I'm not sure, but according to the result of the code above, I can say that the latest version of Swift supported by your Xcode tool becomes the version of Swift Language. p>

0
source

Source: https://habr.com/ru/post/1694844/


All Articles