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:
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?
Xcode can use the different version of the Swift using the build setting $SWIFT_VERSION from the build setting tab of Xcode target if we have other Swift versions available.
To open Playground on Xcode, navigate to File in the menu and click on New > Playground... To test our square function, we will choose the Blank template. Name your Playground file, then click on Create.
One of the biggest differences between Swift Playgrounds and Xcode Playgrounds is that Swift Playgrounds are much less powerful and are built more as an educational tool. My biggest fear is that as Apple brings Swift Playgrounds to the Mac that they will stop supporting and growing Xcode Playgrounds.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With