Mobile Zone is brought to you in partnership with:

Michael Crump is a Microsoft MVP, INETA Community Champion, and an author of several .NET Framework eBooks. He speaks at a variety of conferences and has written dozens of articles on .NET development. He currently works at Telerik with a focus on our XAML control suite. You can visit his blog at: MichaelCrump.Net or follow him on Twitter at: @mbcrump Michael is a DZone MVB and is not an employee of DZone and has posted 114 posts at DZone. You can read more from them at their website. View Full User Profile

Running Swift from the Terminal

07.01.2014
| 2985 views |
  • submit to reddit

After reading through the Apple Developer Docs, I found this:

“Xcode’s debugger includes an interactive version of the Swift language, known as the REPL (Read-Eval-Print-Loop)… you can access it through Xcode’s console, or from Terminal.”

Unfortunately, it does not tell you how to access it from the terminal, but thankfully it is very easy.

Simply enter the following command as shown below (replacing the app name for whichever beta you are using to setup an alias):

alias swift="/Applications/Xcode6-Beta2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift"

You should see the following in your terminal window. Now simply type swift and you will see the welcome message.

terminal

Note: When a new beta comes out just update your alias with the same command, but new app name… i.e. Xcode6-Beta3.app.

You can begin entering your Swift code:

terminal2

Finally, if you type :help as stated when it first runs you have the LLDB debugging commands at your fingertips.

help

Why wouldn’t you just load the Swift Playground?

Good question. I personally love the ability to play with the syntax without launching Xcode 6 Beta and opening a Swift Playground. Also, I am bound to an NDA that says I can’t post screenshots of  Xcode 6 until the final release. This allows me to get around that.


Published at DZone with permission of Michael Crump, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)