Reputation: 150956
I am limited to Xcode 6.2 if I am using Mavericks, and the following code:
let setOfNumbers: Set<Int> = [1, 2, 3, 4, 5];
won't work. So Set
should only work in Swift 1.2 and above. How do I print out what Swift version I am using in the program? (just like p RUBY_VERSION
if using Ruby)
Upvotes: 5
Views: 3307
Reputation: 70096
Updated answer
Starting with Swift 2.2 (Xcode 7.3b) you can determine the Swift version and run code conditionnally with the #if swift()
build configuration.
Example:
#if swift(>=2.2)
print("Running Swift 2.2 or later")
#else
print("Running Swift 2.1 or earlier")
#endif
The branch containing code for the compatible version of Swift will be executed, and the other branch will be ignored.
Old answer
There's no known way to do it in code (ref, ref).
You can do this in the Terminal:
swift -version
For this command to be accurate you need to check that Xcode tools are linked to the proper Xcode version (can be confusing if you have Xcode and Xcode-beta installed side by side).
Upvotes: 7
Reputation: 1114
This is the way you can check in Terminal:
$ xcrun swift -version
It will gives you result.
Upvotes: 5