Setup Swift REPL and Access from the Command Line

Swift has a very nice Read-Eval-Print-Loop (REPL) for developers to take advantage of and be able to get instant feedback on Swift code. This is great for trying things out without having to use Xcode 6 and a full project.

If you are unsure of what this REPL is, from the Swift web site:

Read-Eval-Print-Loop (REPL). The debugging console in Xcode includes an interactive version of the Swift language built right in. Use Swift syntax to evaluate and interact with your running app, or write new code to see how it works in a script-like environment. Available from within the Xcode console, or in Terminal.

The problem is, it’s not available by default since it’s not in your path. If you have Xcode 5 installed you probably don’t want to have to deal with switching back and forth between Xcode paths.

The solution is pretty simple actually. I wanted to be able to get to Swift from the terminal with a short command, in this case, swift will be the command. In order to setup it up I located the swift binary, yours may be different depending upon where you have the Xcode 6 beta installed. Mine was here: