Gaurang Chokhariya
Gaurang Chokhariya

Reputation: 246

How to check, swift version for Playground?

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

One-Sided Ranges

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

now my play ground showing an error:

enter image description here

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

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

How can I see swift version of play ground?

Upvotes: 16

Views: 8207

Answers (3)

Krunal
Krunal

Reputation: 79636

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.

#if swift(>=5.2)
print("Hello, Swift 5.2")
#elseif swift(>=5.1)
print("Hello, Swift 5.1")
#elseif 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 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.

Upvotes: 19

ferbass
ferbass

Reputation: 859

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

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

Upvotes: 3

stevenpcurtis
stevenpcurtis

Reputation: 2001

In the terminal run

swift -version

in all probability playgrounds will be using that version

Upvotes: 0

Related Questions