Running Swift from Sublime Text 3

If you just want to play with Swift’s basics try following:

Inside Sublime Text 3 choose

Tools -> Build System -> New Build System

and replace default entry with (NOTE! make sure everything is a single line)

{
	"shell_cmd": "/Applications/Xcode6-
Beta.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin/swift 
\"${file}\" -o \"${file_path}/${file_base_name}\" 
&& \"${file_path}/${file_base_name}\""
}

Then, type in simple Swift code and press Command-B

println("Hello")

// This is sample array

var stringArray = ["aaa", "bbb", "ccc"]

println(stringArray)

Update!

Pay attention to XCode location

“/Applications/Xcode6-Beta.app”

over time, it will probably change to something like Xcode6-Beta5, Xcode6-Beta6, etc. This will happen as long as XCode is in beta stage.

Update! For XCode6-Beta6

{
	"shell_cmd": "/Applications/Xcode6-
Beta6.app/Contents/Developer/Toolchains/
XcodeDefault.xctoolchain/usr/bin/swiftc 
-target x86_64-apple-macosx10.9 
-sdk /Applications/Xcode6-Beta6.app/Contents/
Developer/Platforms/MacOSX.platform/Developer
/SDKs/MacOSX10.10.sdk \"${file}\" 
-o \"${file_path}/${file_base_name}\" 
&& \"${file_path}/${file_base_name}\""
}

Comments (13)

anonymousJuly 31st, 2014 at 6:52 pm

is this work on windows as well?

anonymousJuly 31st, 2014 at 7:33 pm

I doubt. I am not even able to test whether there is a workaround as I am not a Windows user :(

OS X and Linux only. Sorry.

anonymousAugust 20th, 2014 at 2:05 am

“:0: error: unsupported option ‘-o’ for ‘swift’; did you mean ‘swiftc -o’?”

That’s all I’m getting. Had to add the “5” to the end of the .app name, since I’m running beta 5. Maybe this doesn’t work anymore?

anonymousAugust 20th, 2014 at 9:03 am

You have to replace “Xcode6-Beta.app” with “Xcode6-Beta5.app” inside Sublime script.

anonymousAugust 24th, 2014 at 6:40 pm

How do you deal with multiple swift files where one swift file references another? For example I have a main.swift and support.swift. When I run main.swift, the swiftc claims the classes from support.swift are undefined.

anonymousAugust 24th, 2014 at 7:01 pm

good question.

in fact i was playing with simple cases only.

but this is interesting question.

anonymousSeptember 17th, 2014 at 7:54 am

hi,
im using ubuntu 10.04, and i tried the same procedure,..
when i try to built (Ctrl + b / Ctrl + Shift +b) i cannot view anything.
can any one plz help me..

anonymousSeptember 17th, 2014 at 9:34 am

You need OS X and XCode 6 to get it running.

anonymousSeptember 17th, 2014 at 10:24 am

so i have to install OS X in ubuntu through virtualbox and then install xcode6 inside mac,??
or is there any other way.?

anonymousSeptember 17th, 2014 at 2:12 pm

unfortunately – yes.

you can also try

http://www.runswiftlang.com

anonymousSeptember 17th, 2014 at 10:38 pm

Haa, Thanks ,… U saved my life,.. this would do for me.
Thanks Michal,..
thanks a lot

anonymousSeptember 17th, 2014 at 11:53 pm

have fun :)

anonymousSeptember 25th, 2014 at 5:52 pm

Wow, thanks for online compile!!!