Accidental Technologist

Musings about Entrepreneurship, Technology and Software Development

  • Home
  • About
  • Still River Software
  • Privacy Policy

Powered by Genesis

You are here: Home / Swift / Setup Swift REPL and Access from the Command Line

Setup Swift REPL and Access from the Command Line

June 13, 2014 by Rob Bazinet 8 Comments

Tweet

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:

/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift

If you just run that line in terminal it works fine but I want to be able to access this easily. ?The answer is an alias added to the .bash_profile. ?Add this line to the .bash_profile:

alias swift="/Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift"

Restart the terminal app, type swift and you should see something like this:

Swift term

UPDATE (06/17/2014): Apple released Xcode 6 Beta 2 today and the path changes to where the Swift binary lives, use Xcode6-Beta2.app instead of Xcode6-Beta above.

Share this:

  • LinkedIn
  • Twitter
  • Facebook
  • Email
  • More
  • Pinterest
  • Tumblr
  • Pocket
  • Reddit

Related

Filed Under: Swift Tagged With: swift

Care about your privacy? I do and use Fathom Analytics on this site.

Fathom Analytics

Recent Posts

  • How to Fix Rails Flash Rendering When Using Hotwire
  • Hotwire Fix for CORS Error when using Omniauth
  • Fix Installation of Ruby using rbenv on macOS Big Sur
  • RailsConf 2021 and the Future of Conferences
  • Fixing Out of Diskspace Errors on Amazon EC2

Categories

Services I Love

HatchBox - Easy Rails Deploys Fathom Analytics
Follow @rbazinet

Rob Bazinet
@rbazinet

  • Just for the record and anyone who might consider it...Godaddy is a complete mess and scammy. I don't think I would… https://t.co/755jpkLbnE
    about 3 days ago
  • This is so true and has been my personal take on people complaining they are busy - https://t.co/YW8NTQLXtl
    about 1 week ago
  • Wow…https://t.co/h94ia053sL
    about 1 week ago
  • My Bills lost today but more importantly so did the Dallas Cowboys. Nice seeing the ‘boys done for the season.
    about 2 weeks ago
  • It looks like the Apple Xcode command line tools is a bit bloated for it to take this long… https://t.co/U0HObTvzXf
    about 2 months ago
  • RSS - Posts
  • RSS - Comments