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}\"" }
is this work on windows as well?
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.
“: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?
You have to replace “Xcode6-Beta.app” with “Xcode6-Beta5.app” inside Sublime script.
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.
good question.
in fact i was playing with simple cases only.
but this is interesting question.
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..
You need OS X and XCode 6 to get it running.
so i have to install OS X in ubuntu through virtualbox and then install xcode6 inside mac,??
or is there any other way.?
unfortunately – yes.
you can also try
http://www.runswiftlang.com
Haa, Thanks ,… U saved my life,.. this would do for me.
Thanks Michal,..
thanks a lot
have fun :)
Wow, thanks for online compile!!!