How can I use swift in Terminal?
sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
then you can do one of these:
xcrun swift
lldb --repl
As of Xcode 6.1 - typing swift
in the terminal launches the REPL as well.
How do I see which version of Swift I'm using?
Project build settings have a block 'Swift Compiler - Languages', which stores information about Swift Language Version in key-value format. It will show you all available (supported) Swift Language Version for your Xcode and active version also by a tick mark.
Project ► (Select Your Project Target) ► Build Settings ► (Type
'swift_version' in the Search bar) Swift Compiler Language ► Swift Language
Version ► Click on Language list to open it (and there will be a tick mark on any one of list-item, that will be current swift version).
Look at this snapshot, for easy understanding:
With help of following code, programmatically you can find Swift version supported by your project.
#if swift(>=5.7)
print("Hello, Swift 5.7")
#elseif swift(>=5.6)
print("Hello, Swift 5.6")
#elseif swift(>=5.5)
print("Hello, Swift 5.5")
#elseif swift(>=5.4)
print("Hello, Swift 5.4")
#elseif swift(>=5.3)
print("Hello, Swift 5.3")
#elseif 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.2)
print("Hello, Swift 4.2")
#elseif swift(>=4.1)
print("Hello, Swift 4.1")
#elseif swift(>=4.0)
print("Hello, Swift 4.0")
#elseif swift(>=3.2)
print("Hello, Swift 3.2")
#elseif swift(>=3.0)
print("Hello, Swift 3.0")
#elseif swift(>=2.2)
print("Hello, Swift 2.2")
#elseif swift(>=2.1)
print("Hello, Swift 2.1")
#elseif swift(>=2.0)
print("Hello, Swift 2.0")
#elseif swift(>=1.2)
print("Hello, Swift 1.2")
#elseif swift(>=1.1)
print("Hello, Swift 1.1")
#elseif swift(>=1.0)
print("Hello, Swift 1.0")
#endif
Here is result using Playground (with Xcode 11.x)
Where are the swift/swiftc binaries for v3?
Thanks to Marc B's suggestion:
⇒ find / -name swift -type f
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
/Users/myusername/Desktop/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/bin/swift
/Users/myusername/Desktop/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
/usr/bin/swift
Which for me are:
⇒ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9
⇒ /Users/myusername/Desktop/Xcode-beta.app/Contents/Developer/Toolchains/Swift_2.3.xctoolchain/usr/bin/swift --version
Apple Swift version 2.3 (swiftlang-800.10.6 clang-800.0.24.1)
Target: x86_64-apple-macosx10.9
⇒ /Users/myusername/Desktop/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift --version
Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Target: x86_64-apple-macosx10.9
⇒ /usr/bin/swift --version
Apple Swift version 2.2 (swiftlang-703.0.18.8 clang-703.0.31)
Target: x86_64-apple-macosx10.9
To set v3 as your 'main' swift, you can do the following (make sure to use the right path to your Xcode 8 application):
⇒ sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
⇒ xcrun --find swift
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift
⇒ swift --version
Apple Swift version 3.0 (swiftlang-800.0.30 clang-800.0.24)
Target: x86_64-apple-macosx10.9
Have anyone seen, warning: target specifies SWIFT_VERSION = '2.3'
It looks like the some of your dependencies may be specifying swift 2.3. So it is warning you that this may cause problems in the next upcoming update. You also should check the setting for your project and make sure under project settings that the Use Legacy Swift Language Version' = NO
.
Related Topics
Can Swift Playgrounds See Other Source Files in the Same Project
How to Edit the Uiblureffect Intensity
Class-Only Generic Constraints in Swift
Clearing Uiwebview's Cache in Swift
Understanding the Userdefaults Register Method
Count Number of Decimal Places in a Float (Or Decimal) in Swift
Propertywrappers and Protocol Declaration
Multi-Component Picker (Uipickerview) in Swiftui
How to Utilize Nslock to Prevent a Function from Firing Twice
How to Create Text File for Writing
Navigationview Doesn't Display Correctly When Using Tabview in Swiftui
How to Make Alphabetically Section Headers in Table View with a Mutable Data Source
How to Connect Aksequencer to a Akcallbackinstrument
Avspeechutterance - Swift - Initializing with a Phrase
How to List Swift Types That Conform to Protocol Using Reflection