Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access Swift's REPL? [duplicate]

Tags:

swift

I would like to know how to do this from the CLI so that I can test out some codes without launching Xcode. I saw someone did this but I couldn't find a way to do this yet.

like image 988
Enrico Susatyo Avatar asked Jun 03 '14 23:06

Enrico Susatyo


2 Answers

After installing the Xcode6 beta, do

$ sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/

$ xcrun swift

is a Swift REPL

EDITED:

For XCode 6, use:

xcrun swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk
like image 170
Vinicius Miana Avatar answered Nov 14 '22 04:11

Vinicius Miana


To extend on @vinicius answer, you can also use it without changing your default Xcode by using:

DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift

The easiest way to do that will be to edit your .bashrc and append:

alias swift='DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift'

At that point you'll be able to run it just by typing swift

If you use a csh variant you'll need:

env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift

and create the alias with

alias swift 'env DEVELOPER_DIR=/Applications/Xcode6-Beta.app/Contents/Developer/ xcrun swift'
like image 29
David Berry Avatar answered Nov 14 '22 04:11

David Berry