The successor to Objective-C, Swift was announced by Apple in 2014. Instead of waiting I decided to start learning this language in order to add it to my “bag of tricks” as one of my professors would say. Considering I do not always have a laptop with OSX nearby, my work laptop is Windows, I scoured the internet for a way to have a command-line interface to swift. Something similar to tclsh for TCL or irb for Ruby. What I found was this, but it left me a bit hopeless:
`--> sudo xcode-select -switch /Applications/Xcode.app Password: ``--> lldb --repl Welcome to Swift! Type :help for assistance. println("Hello There!") error: Swift expressions require OS X 10.10 / iOS 8 SDKs or later.
I guess the above may work in a later version of OS X. But, apparently I need OS X 10.10 or iOS 8 SDKs or later to run swift for the command-line. As of now OS X 10.9 is the latest out and it is what I have, see:
`--> sw_vers ProductName: Mac OS X ProductVersion: 10.9.5 BuildVersion: 13F34
And, I also have Xcode 6.0.1, see:
`--> xcodebuild -version Xcode 6.0.1 Build version 6A317
However, it was not until I stumbled upon @swiftLDN twitters page that I learned out how to run swift from the command line. All I needed to do was:
``--> xcrun swift -sdk ios8 <unknown>:0: warning: no such SDK: 'ios8' Welcome to Swift! Type :help for assistance. 1> println("Hello There!") Hello There! 2>
The message about “no such SDK” can be ignored. Apparently, anything can serve as a placeholder after “-sdk”.
Do not get me wrong. Swift works fine in Xcode from the GUI front-end for the current version of OSX and Xcode I have. However, just issuing xcrun swift from the command-line will not cut it just yet.
I hope that help anyone out there.
Cheers!