Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Running Swift from the Terminal

DZone's Guide to

Running Swift from the Terminal

· Java Zone ·
Free Resource

Download Microservices for Java Developers: A hands-on introduction to frameworks and containers. Brought to you in partnership with Red Hat.

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.


Download Building Reactive Microservices in Java: Asynchronous and Event-Based Application Design. Brought to you in partnership with Red Hat

Topics:

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}