I like to use CodeRunner to test out quick snippets of code. I have added Swift as a supported language. I did this by adapting the Objective-C compile.sh script that is used by CodeRunner to compile Objective-C with clang. Hopefully the next release of CodeRunner will support Swift out of the box with a better compiler script and syntax highlighting.
In the CodeRunner Preferences add a new language, check the Language uses compilation script checkbox and edit the script to contain the following:
#!/bin/bash# This is a CodeRunner compilation script. Compilation scripts are used to# compile code before being run using the run command specified in CodeRunner# preferences. This script should have the following properties:## Launch directory ($PWD): Will be the same as the file being run## Exit status: Should be 0 on success (will cause CodeRunner# to continue and execute the run command)## Output (stdout): On success, one line of text which can be accessed# using the $compiler variable in the run command## Output (stderr): Anything outputted here will be displayed in# the CodeRunner console## Arguments: $1 Filename of the source file# $2 Encoding of the source file# $3 Compilation flags set in CodeRunner preferences# $4 Path of a temporary directory (without / suffix)## The encoding argument may be used to specify to the compiler which encoding# the source file uses. It will be one of the integers in the following array:enc=""# UTF-8enc=""# UTF-16enc=""# ISO Latin 1enc=""# ISO Latin 2enc=""# Mac OS Romanenc=""# Windows Latin 1enc=""# Japanese (EUC)enc=""# Japanese (Shift JIS)enc=""# ASCIIcompname=`echo"$1" | sed 's/\(.*\)\..*/\1/'`xcrun swift -sdk $(xcrun --show-sdk-path --sdk macosx)"$1" -o "$compname"$3status=$?if[$status -eq 0 ]thenecho$compnameexit 0
elif[$status -eq 127 ]thenecho -e "\nTo run code in this language, you need to have compilers installed. These are bundled with Xcode 6 or later which can be downloaded through the Mac App Store or Apple's developer site."fiexit$status
The Run Command needs to be set to ./$compiler.
I set my Code Template to the following to include all the Cocoa goodness and set the file extension to swift:
Finally, you’ll probably want to change New Language to Swift by right-clicking in the Language list.
Here is a screenshot of the settings:
In order to allow the xcrun command in the compilation script to find swift you need to ensure that xcode-select is pointing at a version of Xcode that includes the swift compiler, e.g.