Reputation: 246
I was just testing my code in play ground(xcode-8.2), using swift tutorial. I came across following sample code:
for name in names[2...] {
print(name)
}
now my play ground showing an error:
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
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
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
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
Reputation: 2001
In the terminal run
swift -version
in all probability playgrounds will be using that version
Upvotes: 0