Category

Swift REPL

Swift Language

Back in the early 80s I learned the power of LISP’s REPL (Read-Eval-Print-Loop). (As a music major, mind you). Clojure gave us a REPL for the Java JVM. Kids today use Python’s REPL. Swift playgrounds are peachy, but are a bit buggy right now.

Set up

First, you need to say you want to use XCode 6 beta’s Developer Toolchain. Here is the incantation.

(or Xcode6-Beta2.app if you have that installed now)

And to go back to XCode 5:

You might want to define aliases for those in your shell’s .rc file. You could also just set your shell’s DEVELOPER_DIR environment variable to point to it too.

Using the REPL

Find out which SDKs are available:

Then run with one of the listed SDKs.

or

Read the man page xcrun(1) for more info.

Once inside the REPL, you can type :help, or :quit to exit. Control-D works for me too to exit.

Use Swift in a shell script? Chris Lattner tweeted this.

Here’s a simple script.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.