Running Swift from the Terminal
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):
You should see the following in your terminal window. Now simply type swift and you will see the welcome message.
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:
Finally, if you type :help as stated when it first runs you have the LLDB debugging commands at your fingertips.
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.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)