Over a million developers have joined DZone.

A Better way to Access Swift From the Terminal

·

A Better Way to Access Swift From the Terminal

Introduction

In my original post, I described how to create an alias to run Swift from the terminal. The only problem was when the user closed the terminal window, they would have to run the 'alias' command again. In this short tutorial, we are going to setup a way that the alias "sticks" between terminal sessions.

Open the Terminal Window Again

Enter the follow command to open your .bash_profile in TextEdit:

touch ~/.bash_profile; open ~/.bash_profile

Enter the following command in TextEdit changing only the Xcode6-BetaXX number (for whichever version of the beta you are using):

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

Save the File by pressing CMD+S and quit TextEdit by pressing CMD-Q.

Return to the terminal window and type:

source ~/.bash_profile

This will load the bash file without having to reboot.

Now if you simply type swift then you can access the Swift REPL.

After a Reboot

Simply type swift from the terminal without having to set the alias again since it was loaded during startup in your .bash_profile.

Topics:

Published at DZone with permission of Michael Crump. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}